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

PHP generates random numbers custom function randstr($length)

巴扎黑
巴扎黑 Original
2016-11-24 09:09:50 1628browse

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