欢迎来到福编程网,本站提供各种互联网专业知识!

PHP产生随机字符串函数

发布时间:2006-12-06 作者: 来源:转载

/**
*产生随机字符串
*
*产生一个指定长度的随机字符串,并返回给用户
*
*@accesspublic
*@paramint$len产生字符串的位数
*@returnstring
*/
functionrandStr($len=6){
$chars='ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*';//characterstobuildthepasswordfrom
mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return$password;
}

?>

相关推荐