天天看點

生成随機指定長度的字元串

/**
 *生成随機指定長度的字元串
*/
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;
}      

轉載于:https://www.cnblogs.com/spectrelb/p/5999189.html