Home  >  Article  >  Backend Development  >  Generate string + numeric random number of any length_PHP tutorial

Generate string + numeric random number of any length_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:42:59692browse

You can customize what string is generated and how long it is

[PHP] Code

Function random($length)

 {

 $hash = ;

$chars = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz;

 $max = strlen($chars) - 1;

mt_srand((double)microtime() * 1000000);

 for($i = 0; $i < $length; $i++)

 {

 $hash .= $chars[mt_rand(0, $max)];

 }

return $hash;

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486024.htmlTechArticleYou can customize what string is generated and how long it is [PHP] code function random($length) { $hash = ; $chars = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz; $max = st...
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