php生成不重复随机字符串


使用时间戳作为原始字符串,再随机生成五个字符随机插入任意位置,生成新的字符串,保证不重复

 1     function rand($len)
 2     {
 3         $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
 4         $string=time();
 5         for(;$len>=1;$len--)
 6         {
 7             $position=rand()%strlen($chars);
 8             $position2=rand()%strlen($string);
 9             $string=substr_replace($string,substr($chars,$position,1),$position2,0);
10         }
11         return $string;
12     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM