This article describes the PHP source code Analysis of DZX1.5 random number function random usage. Share to everyone for your reference. Specifically as follows:
<?php
/**
* @param int $length: Random number length
* @param int $numeric: 0 or not 0, where 0 indicates that the random number consists of a full number, and a non 0 indicates that the random number consists of a full letter
* @ Return string: Returns the generated random number
/function random ($length, $numeric = 0) {
$seed = Base_convert (MD5 microtime (). $_ server[' Document_root '), $numeric? 10:35);
$seed = $numeric? (Str_replace (' 0 ', ', $seed). " 012340567890 '): ($seed. ' ZZ '. Strtoupper ($seed));
$hash = ';
$max = strlen ($seed)-1;
for ($i = 0; $i < $length; $i + +) {
$hash. = $seed {mt_rand (0, $max)};
}
return $hash;
}
echo Random (' 1 ');
echo ' <br/> ';
echo Random (' a ');
/*end of php*/
The results of the operation are as follows:
228283270677112
Sjqffsu76994qfs
I hope this article will help you with your PHP program design.