The rand() function in PHP is used to generate random integers ranging from 0 to RAND_MAX (default 2147483647). You can specify the minimum and maximum values as parameters, and the function returns a random integer between the two values.
Usage of rand() function in PHP
rand() function is a built-in function for Generate random numbers. It generates a random integer ranging from 0 to RAND_MAX, which is a constant and defaults to 2147483647.
Syntax:
<code class="php">int rand([int $min [, int $max]])</code>
Parameters:
Return value:
The function returns a random integer between $min and $max (inclusive of bounds).
Example:
<code class="php">// 生成一个随机数(0-2147483647) $num = rand(); // 生成一个随机数(10-100) $num = rand(10, 100);</code>
Note:
The above is the detailed content of How to use rand() function in php. For more information, please follow other related articles on the PHP Chinese website!