Maison  >  Article  >  développement back-end  >  php生成随机数 自定义函数 randstr($length)

php生成随机数 自定义函数 randstr($length)

巴扎黑
巴扎黑original
2016-11-24 09:09:501634parcourir

function randstr($len=6){ 
    $chars='abcdefghijklmnopqrstuvwxyz0123456789'; 
    #characters to build the password from 
    mt_srand((double)microtime()*1000000*getmypid()); 
    #seed the random number generater (must be done) 
    $password=''; 
    while(strlen($password)<$len) 
        $password.=substr($chars,(mt_rand()%strlen($chars)),1); 
    return $password; 


$salt = randstr();

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn