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: |
Copy code |
$ Random = rand (0,1000 );
Or <? Php $ Rand = mt_rand (1,100 ); Echo $ rand; ?> |
Example 2
| The code is as follows: |
Copy code |
Srand (double) microtime () * 1000000 ); $ Random = rand (0,1000 ); |
Example 3
| The code is as follows: |
Copy code |
/** * 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 random array arrangement function. Return array_slice ($ rand_array, 0, $ limit); // The first $ limit } |