使用时间戳作为原始字符串,再随机生成五个字符随机插入任意位置,生成新的字符串,应该不会再重复了,重复抓紧买彩票!!!
<?php function randstr($len) { $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $string=time(); for($len;$len>=1;$len--) { $position=rand()%strlen($chars); $position2=rand()%strlen($string); $string=substr_replace($string,substr($chars,$position,1),$position2,0); } return $string; } echo randstr(10); ?>