Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

RAND

Example

Provide a random decimal number (without specifying a seed value, ensuring it’s entirely random and falls within the range of greater than or equal to 0 and less than 1).

SELECT RAND();

Definition and Usage

The RAND() function generates a random number ranging from 0 (inclusive) to 1 (exclusive).

Syntax

RAND(seed)

Parameter Values

Parameter

Description

seed

When a seed is specified, the RAND() function produces a sequence of random numbers that can be replicated. When no seed is specified, it generates entirely random numbers.

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Provide a random decimal number using a seed value of 6.

SELECT RAND(6);

Example

Generate a random decimal number that is greater than or equal to 5 and less than 10.

SELECT RAND()*(105)+5;

Example

Generate a random number that falls within the range of 5 to 10, inclusive.

SELECT FLOOR(RAND()*(105+1)+5);