bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

MySQL RAND() Function

Concept visual

MySQL RAND() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Formula

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

Definition and Usage

The RAND() function returns a random number between 0 (inclusive) and 1 (exclusive).

Syntax

Rand(

seed )

Parameter Values

Parameter

Description seed

Optional. If seed is specified, it returns a repeatable sequence of random numbers. If no seed is specified, it returns a completely random number

Technical Details

Works in:

From MySQL 4.0

More Examples

Example

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

SELECT RAND(6);

Example

Formula

Return a random decimal number >= 5 and < 10:
SELECT RAND()*(10-5)+5;

Example

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

SELECT FLOOR(RAND()*(10-5+1)+5);

Previous

❮ MySQL Functions

Next

Previous

MySQL RADIANS() Function

Next

MySQL ROUND() Function