Home >php教程 >php手册 >产生任意长度的字符串+数字随机数

产生任意长度的字符串+数字随机数

WBOY
WBOYOriginal
2016-06-21 08:55:461058browse

   可以自定义产生什么字符串以及多长

     [PHP]代码

  function random($length)

  {

  $hash = '';

  $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';

  $max = strlen($chars) - 1;

  mt_srand((double)microtime() * 1000000);

  for($i = 0; $i

  {

  $hash .= $chars[mt_rand(0, $max)];

  }

  return $hash;

  }




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