THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL RAND() Function

❮ MySQL Functions

Example

Return a random decimal number (no seed value - so it returns a completely random number >= 0 and <1):

SELECT RAND();
Try it Yourself »

Definition and Usage

The RAND() function returns a random number or a random number within a range.

The RAND() function will return a value between 0 (inclusive) and 1 (exclusive).

The RAND() function will return a completely random number if no seed is provided, and a repeatable sequence of random numbers if a seed value is used.

Syntax

RAND(seed)

Parameter Values

Parameter Description
seed Optional. If specified, it produces a repeatable sequence of random numbers each time that seed value is provided

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

More Examples

Example

Return a random decimal number (with seed value of 6):

SELECT RAND(6);
Try it Yourself »

Example

Return a random decimal number >= 5 and <10:

SELECT RAND()*(10-5)+5;
Try it Yourself »

Example

Return a random number >= 5 and <=10:

SELECT FLOOR(RAND()*(10-5+1)+5);
Try it Yourself »

❮ MySQL Functions