<?php
function getrandomstring($len,$chars=null){
if(is_null($chars)){
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
}
mt_srand(1000*(double)time());
$str = '';
for($i = 0,$lc = strlen($chars)-1;$i<$len;$i++){
$str.= $chars[mt_rand(0,$lc)];
}
return $str;
}
$a = getrandomstring(5);
var_dump($a);
//打印生成一个5位的随机数