PHP: mt_rand() function
Description
The mt_rand() function is used to generate a random integer using the Mersenne Twister algorithm.
Version:
(PHP 4 and above)
Syntax:
mt_rand() mt_rand( minv, maxv )
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
minv | Lowest value to be returned. Default : 0 |
Optional | Integer |
maxv | Highest value to be returned. Default: mt_getrandmax()) |
Optional | Integer |
Note: If the function is called without the minv and maxv arguments mt_rand() returns a pseudo-random value between 0 and mt_getrandmax(). If you want a random number between 10 and 15 (inclusive), for example, use mt_rand(10, 15).
Return value:
A random number value between minv (or 0) and maxv.
Value Type: Integer.
Example:
<?php
echo(mt_rand() . "<br />");
echo(mt_rand(10,15))
?>
View the example in the browser
See also
Previous: mt_getrandmax
Next: mt_srand
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/mt_rand.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics