Easy Tutorial
❮ Func Mysqli Errno Func Mysqli Kill ❯

PHP rand() Function

PHP Math Reference Manual

Example

Generate a random number:


Definition and Usage

The rand() function generates a random integer.

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

Tip: The mt_rand() function is a better choice for generating random values, as it returns results four times faster than rand().

Syntax

Parameter Description
min Optional. Specifies the minimum number to return. Default is 0.
max Optional. Specifies the maximum number to return. Default is getrandmax()

Technical Details

Return Value: A random integer between min (or 0) and max (or mt_getrandmax()), inclusive.
Return Type: Integer
--- ---
PHP Version: 4+
--- ---
PHP Changelog: PHP 4.2.0: The random number generator is automatically seeded.
--- ---
❮ Func Mysqli Errno Func Mysqli Kill ❯