Generate random data in PHP we can use Rand,mt_rand can be generated in the specified range of random data, the following for you to introduce the method of the students
Call Mt_rand () This method can generate random numbers, which are the minimum and maximum values of the range, and the function returns a random number between the minimum and maximum values.
To generate a true random number is not an easy task for computing.
There are two methods in PHP that can generate random numbers, a classic function called 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, +); Echo $rand;? >
Example 2
The code is as follows
Srand (Double) microtime () *1000000); $random =rand (0,1000);
Example 3
The code is as follows
/** * Get multiple random numbers within a certain range */function yang_numberrand ($begin = 0, $end = 5, $limit =) { $rand _array = Range ($begin, $end); Shuffle ($rand _array);//Call out-of-the-box array random permutation function return array_slice ($rand _array, 0, $limit);//Pre-intercept $limit}
Summary: The above is the entire content of this article, I hope to be able to help you learn.