当前位置:Gxlcms > PHP教程 > php生成随机数自定义函数randstr($length)

php生成随机数自定义函数randstr($length)

时间:2021-07-01 10:21:17 帮助过:67人阅读

function randstr($len=6){
$chars='abcdefghijklmnopqrstuvwxyz0123456789';
#characters to build the password from
mt_srand((double)microtime()*1000000*getmypid());
#seed the random number generater (must be done)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}

$salt = randstr();

人气教程排行