Php source code analysis-DZX1.5 random number function random usage, dzx1.5random
This article describes how to use the DZX1.5 random number function random in php source code analysis. Share it with you for your reference. The details are as follows:
<? Php/*** @ param int $ length: Random Number length * @ param int $ numeric: 0 or not 0, where 0 indicates that the random number is composed of all numbers, A non-0 random number is composed of all letters * @ return string: returns the generated random Number */function random ($ length, $ numeric = 0) {$ seed = base_convert (md5 (microtime (). $ _ SERVER ['document _ root']), 16, $ numeric? 10: 35); $ seed = $ numeric? (Str_replace ('0', '', $ seed ). '20140901'): ($ 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 ('15', 1); echo '<br/> '; echo random ('15');/* End of php */
The running result is as follows:
228283270677112
SjqffsU76994qfS
I hope this article will help you with php programming.