php 随机函数

来源:百度知道 编辑:UC知道 时间:2024/05/23 13:16:22
36cd0022-5adf-041f-bbd2-49e6e38070f3 这么长的一个字符串,在PHP的函数库里面有没有啊,要是没,这个函数怎么写啊,谢谢

你是16进制数,用rand()或mt_rand()分段生成再拼起来。

随机字符串生成法:
function randomkeys($length)
{
$output='';
for ($a = 0; $a < $length; $a++) {
$output .= chr(mt_rand(33, 126)); //生成php随机数
}
return $output;
}
echo randomkeys(8);

其中,mt_rand()生成一个介于33到126之间的php随机数,然后用chr()函数转化成字符。