PHP code to generate random numbers or strings_PHP tutorial

WBOY
Release: 2016-07-21 15:50:07
Original
810 people have browsed it

$len represents the length, the code is as follows:

Copy code The code is as follows:

/**
* Generate a random string
*
* Generate a random string of specified length and return it to the user
*
* @access public
* @param int $len generate Number of digits in string
* @return string
*/
function randstr($len=6) {
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz0123456789-@#~';
// characters to build the password from
mt_srand((double)microtime() *1000000*getmypid());
// seed the random number generator (must be done)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319425.htmlTechArticle$len represents the length, the code is as follows: Copy the code The code is as follows: /** * Generate a random string* * Generate A random string of specified length and returned to the user * * @access public * @param i...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template