Home > php教程 > php手册 > body text

php中mt_rand()随机数函数用法

WBOY
Release: 2016-06-06 20:17:00
Original
1617 people have browsed it

这篇文章主要介绍了php中mt_rand()随机数函数用法,较为详细的分析了mt_rand()随机数函数的常见用法,并结合数组遍历给出了数组随机输出的实例,需要的朋友可以参考

本文实例讲述了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).

PHP实例代码如下:

复制代码 代码如下:

$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";
}

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
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 Recommendations
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!