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

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
相关推荐
dog25014 小时前
细看高维空间中距离度量失效
开发语言·php
二等饼干~za89866815 小时前
源码可控:云罗 GEO 源头工厂,开源搭建 + 二次开发全链路解决方案
服务器·开发语言·开源·php·音视频·ai-native
zhanghongbin0115 小时前
本地持久化:网络故障数据保护
服务器·网络·php
软件开发技术15 小时前
最新版310版本绿豆UI9+后台源码+TV版APK+手机版APK
php
liliangcsdn16 小时前
sentence-transformer如何离线加载和使用模型
开发语言·前端·php
AI应用实战 | RE17 小时前
011、向量数据库入门:Embeddings原理与ChromaDB实战
开发语言·数据库·langchain·php
KKKlucifer18 小时前
零信任融合 4A 平台,构建全域身份动态可信管控体系
开发语言·php
TE-茶叶蛋19 小时前
在 ThinkPHP 5.1 项目中创建一个新的模块
php
无心使然云中漫步19 小时前
ArcGis常用服务介绍及Arcgis,Openlayers,Leaflet加载
开发语言·arcgis·php
软件开发技术21 小时前
最新在线留言板系统PHP源码
开发语言·php·留言板系统php源码