php The mt_rand() function is used to generate random integers within a specified range. The syntax is "mt_rand();" or "mt_rand(min,max);". If no parameters are specified, a pseudo-random number between 0 and RAND_MAX is returned; if the parameters are specified, a random integer between min and max (including boundary values) is returned.
How to use the mt_rand() function?
The mt_rand() function uses the Mersenne Twister algorithm to generate random integers within the specified range.
Syntax:
mt_rand(X,Y)
Parameters:
X represents the minimum number in the range
Y represents the maximum number in the range
Description: From Get a random number within the range of two parameters. The random number is greater than or equal to X or less than or equal to Y
php mt_rand() function example 1
<?php $i = 1; $j = 9; $k = mt_rand($i,$j); echo "取得的随机数为".$k; ?>
Output:
取得的随机数为5
php mt_rand() function example 2
<?php $i = 10; $j = 99; $k = mt_rand($i,$j); echo "取得的随机数为".$k; ?>
Output:
取得的随机数为24
The above is the detailed content of How to use php mt_rand function. For more information, please follow other related articles on the PHP Chinese website!