PHP mt_rand() Function
Example
Generate a random number:
"); echo(mt_rand() . ""); echo(mt_rand(10,100)); ?>
Run Example »
Definition and Usage
The mt_rand() function generates random integers using the Mersenne Twister algorithm.
**Tip:** This function is a better choice for generating random values, returning results rand() 4 times faster than the rand() function.
**Tip:** If you want a random integer between 10 and 100 (inclusive), use mt_rand(10,100).
Syntax
mt_rand();
or
mt_rand(
min,max
);
| Parameters | Description |
|---|---|
| min | Optional. Specifies the minimum number to return. Default is 0. |
| max | Optional. Specifies the maximum number to return. Default is mt_getrandmax(). |
Technical Details
| Return Value: | Between min(or 0) and max(or mt_getrandmax()), inclusive. If max < min then FALSE is returned. |
|---|---|
| Return Type: | Integer |
| PHP Version: | 4+ |
| PHP Changelog: | PHP 4.2.0: The random number generator is seeded automatically. |
| PHP 5.3.4: If max < min an E_WARNING is issued and FALSE is returned. |
PHP Math Reference Manual