Home > Article > Backend Development > php mt_rand() random number function_PHP tutorial
php tutorial mt_rand() random number function
mt_rand() returns a random integer using the mersenne twister algorithm.
Grammar
mt_rand(min,max) description
If the optional arguments min and max are not provided, mt_rand() returns a pseudorandom number between 0 and rand_max. For example, if you want a random number between 5 and 15 (inclusive), use mt_rand(5, 15).
In versions prior to 3.0.7, max meant range. To get the same random numbers from 5 to 15 as in the above example in these versions, the short example is 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";
}