Easy Tutorial
❮ Func Ftp Get Option Func Array Rand ❯

PHP mt_rand() Function

PHP Math Reference Manual

Example

Generate a random number:


Definition and Usage

The mt_rand() function generates a random integer using the Mersenne Twister algorithm.

Note: This function is a better choice for generating random values, as it is four times faster than the rand() function.

Note: If you want a random integer between 10 and 100 (inclusive), use mt_rand(10, 100).


Syntax

Parameter Description
min Optional. Specifies the minimum number to be returned. Default is 0.
max Optional. Specifies the maximum number to be returned. Default is mt_getrandmax()

Technical Details

Return Value: A random integer between min (or 0) and max (or mt_getrandmax()), inclusive. Returns FALSE if max < min.
Return Type: Integer
--- ---
PHP Version: 4+
--- ---
PHP Changelog: PHP 4.2.0: The random number generator is automatically seeded. <br>PHP 5.3.4: Reports an E_WARNING and returns FALSE if max < min.
--- ---
❮ Func Ftp Get Option Func Array Rand ❯