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

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
相关推荐
求学中--2 小时前
鸿蒙网络请求从入门到精通:HttpURLConnection+第三方库,GET/POST/文件上传全覆盖
开发语言·php·harmonyos
yaodong5182 小时前
Gemini长上下文重塑RAG架构
开发语言·php
fengci.2 小时前
CTF+随机困难部分
android·开发语言·网络·安全·php
自不量力的A同学3 小时前
PHP 8.5.6 发布
开发语言·php
Web极客码3 小时前
2026年自建网站实战指南:从服务器到上线的完整方案
运维·服务器·php
念何架构之路3 小时前
负载均衡详解
运维·php·负载均衡
小闫BI设源码4 小时前
当20个节点选出两个Master时:Elasticsearch的致命故障与解决方案
java·elasticsearch·jenkins·php·面试宝典·深入解析
ljh5746491194 小时前
thinkphp8 event
php
爱吃提升5 小时前
Yifan Hu(适合大规模数据)大数据算法
开发语言·算法·php
树下水月6 小时前
php artisan serve 在window上执行报错的问题
开发语言·php