Home >Backend Development >PHP Tutorial >PHP generates random numbers with custom function randstr($length)

PHP generates random numbers with custom function randstr($length)

巴扎黑
巴扎黑Original
2016-11-23 11:51:172622browse

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();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn