DZX1.5 random number function random sharing

WBOY
Release: 2016-07-25 09:09:20
Original
978 people have browsed it
DZX1.5 随机数
  1. /**
  2. * @param int $length: Random number length
  3. * @param int $numeric: 0 or non-0, where 0 means the random number consists of all numbers, non-0 means the random number consists of all letters
  4. * @return string: Return Generated random numbers
  5. */
  6. function random($length, $numeric = 0) {
  7. $seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  8. $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
  9. $hash = '';
  10. $max = strlen($seed) - 1;
  11. for($i = 0; $i < $length; $i++) {
  12. $hash .= $seed{mt_rand(0, $max)};
  13. }
  14. return $hash;
  15. }
  16. echo random('15',1);
  17. echo '
    ';
  18. echo random('15');
  19. /*End of php*/
复制代码


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!