生成随机指定长度的字符串

/**
 *生成随机指定长度的字符串
*/
public static function stringGenerate($length){
$str = null;
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789_abcdefghijklmnopqrstuvwxyz";
$max = strlen($strPol)-1;

for($i=0;$i<$length;$i++){
$str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
}
return $str;
}

 

posted @ 2016-10-26 09:49  spectrelb  阅读(1604)  评论(0编辑  收藏  举报