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 about how to use the mt_rand () random number function in php, see the following example. 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, mt_rand () are not provided, a pseudo-random number between 0 and rand_max is returned, for example, a random number between 5 and 15 (including 5 and 15) is required, 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.