This article mainly introduces the usage of the mt_rand () random number function in php, analyzes the common usage of the mt_rand () random number function in detail, and provides an example of random output in combination with array traversal, for more information, see
This article mainly introduces the usage of the mt_rand () random number function in php, analyzes the common usage of the mt_rand () random number function in detail, and provides an example of random output in combination with array traversal, for more information, see
This example describes the usage of the mt_rand () random number function in php. Share it with you for your reference. The specific analysis is as follows:
Mt_rand () returns a random integer using the mersenne twister algorithm.
Syntax: mt_rand (min, max)
Note: If the optional parameters min and max are not provided, the mt_rand () returns a pseudo-random number between 0 and rand_max, for example, a random number between 5 and 15 (including 5 and 15, use mt_rand (5, 15 ).
In versions earlier than 3.0.7, max indicates range. In these versions, a random number of 5 to 15 is obtained, which is the same as that in the previous example. In a short example, mt_rand (5, 11 ).
The PHP instance code is as follows:
The Code is as follows:
$ Rand = mt_rand (0, 1 );
If ($ rand = 0)
{
$ Array = array (, 30 );
}
Elseif ($ rand = 1)
{
$ Array = array (37,400,444 );
}
Foreach ($ array as $ v => $ vv)
{
Echo "$ vvn ";
}
I hope this article will help you with PHP programming.