Home  >  Article  >  php教程  >  php mt_rand()随机数函数

php mt_rand()随机数函数

WBOY
WBOYOriginal
2016-06-13 11:18:481294browse

 

php教程 mt_rand()随机数函数
mt_rand() 使用 mersenne twister 算法返回随机整数。

语法
mt_rand(min,max)说明
如果没有提供可选参数 min 和 max,mt_rand() 返回 0 到 rand_max 之间的伪随机数。例如想要 5 到 15(包括 5 和 15)之间的随机数,用 mt_rand(5, 15)。

在 3.0.7 之前的版本中,max 的含义是 range 。要在这些版本中得到和上例相同 5 到 15 的随机数,简短的例子是 mt_rand (5, 11)。
*/

 $rand = mt_rand(0,1);
 if( $rand==0 )
 {
  $array = array(41,20,26,29,30);
 }
 elseif( $rand==1 )
 {
  $array = array(38,42,37,400,444);
 }

 foreach( $array as $v => $vv )
 {
  
  echo "$vvn";
 }


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