Usage of mt_rand of Random Number Function in php

  • 2021-08-05 09:17:53
  • OfStack

This article illustrates the use of the mt_rand () random number function in php. Share it for your reference. The specific analysis is as follows:

mt_rand () returns random integers using the mersenne twister algorithm.

Syntax: mt_rand (min, max)

Note: If optional parameters min and max are not provided, mt_rand () returns pseudo-random numbers between 0 and rand_max. For example, if you want random numbers between 5 and 15 (including 5 and 15), use mt_rand (5, 15).

In versions prior to 3.0. 7, max meant range, and to get the same random numbers from 5 to 15 in these versions as in the previous example, a short example is mt_rand (5, 11).

The PHP example code is as follows:

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

I hope this article is helpful to everyone's PHP programming.


Related articles: