可阅读随机字符串与随机字符串

1、将创建一个可阅读的字符串,使其更接近词典中的单词,实用且具有密码验证功能。

php 复制代码
/**  
* @param length - length of random string (must be a multiple of 2)  
* @参数length-随机字符串的长度(必须是2的倍数)
*/ 
function readable_random_string($length = 6){
	$conso = array("b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z");
	$vocal = array("a","e","i","o","u");
	$password = "";
	srand ((double)microtime()*1000000);	//srand()-播下随机数发生器种子,microtime --- 返回当前 Unix 时间戳和微秒数
	$max = $length / 2;
	for($i = 0; $i < $max; $i++){
		$password .= $conso[rand(0,20)];
		$password .= $vocal[rand(0,5)];
	}
	return $password;
}

print_r(readable_random_string());
//输出示例为:xaciti

2、创建一个随机字符串,作为用户的随机密码

php 复制代码
/**  
*@param $length - length of random string  
*@length-随机字符串的长度
*/ 

function generate_random_string($length){
	$c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	$rand = "";
	srand((double)microtime()*1000000);
	for($i = 0; $i < $length; $i++){
		$rand .= $c[rand()%strlen($c)];
	}
	return $rand;
}

print_r(generate_random_string(6));
//输出示例为:QNXM5w
相关推荐
BingoGo6 小时前
PHP 泛型之殇 泛型 RFC 提案被拒绝
后端·php
JaguarJack6 小时前
PHP 泛型之殇 泛型 RFC 提案被拒绝
后端·php
用户3074596982071 天前
PHP 扩展——从入门到理解
php
鹏仔先生2 天前
拷贝漫画APP下载页PHP程序,后台带免费AI写作
php
云水一下2 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php
xingpanvip2 天前
星盘接口开发文档:本命盘接口指南
android·开发语言·css·php·lua
酉鬼女又兒2 天前
零基础入门计算机网络运输层:端到端通信核心作用、端口号分类规则、复用分用工作机制及UDP与TCP协议全方位对比详解
网络·网络协议·tcp/ip·计算机网络·考研·udp·php
dog2502 天前
不要再继续优化 TCP
网络协议·tcp/ip·php
Channing Lewis2 天前
PHP 解析 Excel 的那些坑:一次“行号错位”引发的数据丢失
开发语言·php·excel
Cheng小攸2 天前
渗透行为分析与检测
开发语言·php