Multiple Random Number Code instances and random number instances within the range specified by php
Call mt_rand () to generate a random number. The parameter is the minimum and maximum values of the range. The function returns a random number between the minimum and maximum values.
Generating real random numbers is not easy for calculation.
In php, two methods can generate random numbers. One classic function is rand (), and the other better function is mt_rand ().
Example 1
The Code is as follows:
$ Random = rand (0,1000 );
Or
<? Php $ rand = mt_rand (1,100); echo $ rand;?>
Example 2
The Code is as follows:
Srand (double) microtime () * 1000000); $ random = rand );
Example 3
The Code is as follows:
/**
* Obtain multiple random numbers in a certain range.
*/Function yang_numberRand ($ begin = 0, $ end = 20, $ limit = 5) {$ rand_array = range ($ begin, $ end); shuffle ($ rand_array ); // call the ready-made random array arrangement function return array_slice ($ rand_array, 0, $ limit); // cut the first $ limit}
Through this article, I hope to help my friends who encounter this problem in PHP programming!