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

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
相关推荐
ESDWAN4 小时前
SD-WAN 主备切换为什么仍然会断网?从检测机制到会话恢复分析
开发语言·php
yunlaodacom6 小时前
腾讯云国际站服务代理商:CVM连接TencentDB失败排查指南
云计算·php·腾讯云
脏脏a7 小时前
延迟与画质:远程控制的生命线
开发语言·php
一条破秋裤7 小时前
SDIO Wi‑Fi 设备的驱动向insmod + 反向rmmod
开发语言·php
weixin_417396838 小时前
星级酒店境外电视频道怎么合法接入?合规要点与核对清单
开发语言·前端·php·1024程序员节·综合布线
4SAPI9 小时前
会议智能处理大模型 API 生产选型指南:4SAPI、硅基流动与 OpenRouter 的架构权衡
人工智能·架构·自动化·gateway·php
汤姆宝库10 小时前
具身智能深拆:VLA、世界模型与数据飞轮
开发语言·人工智能·php
云老大-阿里云国际站代理商13 小时前
阿里云国际站渠道代理商:ECS 怎么对接 OSS?权限、域名、网络路径怎么配置?
网络·阿里云·php
昵称画14 小时前
图文:一张十年前的车间系统架构图
低代码·系统架构·php·企业微信·rxjava·零售
tommyjiatong14 小时前
什么是PHP漏洞
开发语言·php