Home >Backend Development >PHP Tutorial >PHP generates string + numeric random number of arbitrary length

PHP generates string + numeric random number of arbitrary length

WBOY
WBOYOriginal
2016-07-25 08:44:23897browse

You can customize what string is generated and how long

  1. function random($length)
  2. {
  3. $hash = '';
  4. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  5. $max = strlen($ chars) - 1 ;
  6. mt_srand((double)microtime() * 1000000);
  7. for($i = 0; $i < $length; $i++)
  8. {
  9. $hash .= $chars[mt_rand(0, $max)] ;
  10. }
  11. return $hash;
  12. }
Copy code

PHP


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