php案列分享

                                            

<?php

function GetfourStr($len)

{

  $chars_array = array(

    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",

    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",

    "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",

    "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",

    "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",

    "S", "T", "U", "V", "W", "X", "Y", "Z",

  );

  $charsLen = count($chars_array) - 1;

  

  $outputstr = "";

  for ($i=0; $i<$len; $i++)

  {

    $outputstr .= $chars_array[mt_rand(0, $charsLen)];

  }

  return $outputstr;

}

echo GetfourStr(4);

?>

 其中部分函数解析:mt_rand函数说明:mt_rand()返回随机整数。

                                     如果没有提供可选参数 min 和 max,mt_rand() 返回 0 到 RAND_MAX 之间的伪随机数。

         例如想要 0 到 46(包括 0 和 46)之间的随机数,用 mt_rand(0, 46)。

原文地址:https://www.cnblogs.com/xa4312cs/p/6139702.html