PHP生成随机数的两种方法
PHP生成随机数的两种方法这里整理了php生成随机数的二种方法,入门级的php随机数生成代码。:
第一种方法,使用系统自带的函数:
srand((double)microtime()*1000000);
//随机产生0-99之间的整数
$randval=rand(0,99999999);
echo $randval,'';
第二种方法,不只是生成只有数字的随机字符串,更包括了各种特殊字符:
function randomkeys($length){
$output='';
for($a=0;$a<$length; $a++){
$output.=chr(mt_rand(33, 126));
} // www.yuju100.com
return $output;
}
echo randomkeys(20);
页:
[1]