Php source code analysis-DZX1.5 random number function random usage
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:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<? Php /** * @ Param int $ length: Random Number length * @ Param int $ numeric: 0 or non-0. 0 indicates that a random number is composed of all numbers. A non-0 indicates that a 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). '000000'): ($ 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.