Php generates the random number mt_rand () rand () mt_srand () function. Mt_rand () returns a random integer using the mersennetwister algorithm. Syntax mt_rand (min, max) indicates that if the optional parameters min and max are not provided, mt_rand () returns the pseudo value between 0 and rand_max with mt_rand () and returns a random integer using the mersenne twister algorithm.
Syntax
Mt_rand (min, max) description
If the optional parameters min and max are not provided, mt_rand () returns a pseudo-random number between 0 and rand_max. For example, if you want a random number between 5 and 15 (including 5 and 15), use mt_rand (5, 15 ).
*/
Echo mt_rand (); // generates a random number.
Echo"
";
Echo mt_rand (); // generates a random number.
Echo"
";
Echo mt_rand (10,100); // Generate 10 ~ Random number between 00
/*
Mt_srand () seeding mersenne twister random number generator.
Syntax
Mt_srand (seed) parameter description
Seed is required. Seed is used to seeding the random number generator.
Description
Starting from php version 4.2.0, the seed parameter is changed to an optional parameter. If this parameter is left blank, it is set to the number at any time.
*/
Function make_seed () // generates a random seed.
{
List ($ usec, $ sec) = explode ('', microtime (); // splits the current number of milliseconds
Return (float) $ sec + (float) $ usec * 100000); // return value
}
Mt_srand (make_seed (); // seeding for the random number generator
$ Randval = mt_rand (); // generates a random number.
Echo $ randval; // output result
/*
The rand () function returns a random integer.
Syntax
Rand (min, max) parameter description
Min, max (optional. Specifies the range of random numbers.
Description
If the optional parameters min and max are not provided, rand () returns a pseudo-random integer between 0 and rand_max. For example, if you want a random number between 5 and 15 (including 5 and 15), use rand (5, 15 ).
*/
Echo rand (); // generates a random number.
Echo"
";
Echo rand (); // generates a random number.
Echo"
";
Echo rand (5, 15); // generates 5 ~ Random number between 15
/*
Note: in some platforms (such as windows), rand_max only has 32768. If the required range is greater than 32768, specify the min and max parameters to generate a number greater than rand_max, or use mt_rand () to replace it.
*/
Http://www.bkjia.com/PHPjc/631709.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631709.htmlTechArticlemt_rand () returns a random integer using the mersenne twister algorithm. The syntax mt_rand (min, max) indicates that if the optional parameters min and max are not provided, mt_rand () returns the pseudo-accompanied value between 0 and rand_max...