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(); |
The RAND() function generates a random number ranging from 0 (inclusive) to 1 (exclusive).
| RAND(seed) |
|
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. |
|
Works in: |
From MySQL version 4.0 |
Provide a random decimal number using a seed value of 6.
| SELECT RAND(6); |
Generate a random decimal number that is greater than or equal to 5 and less than 10.
| SELECT RAND()*(10–5)+5; |
Generate a random number that falls within the range of 5 to 10, inclusive.
| SELECT FLOOR(RAND()*(10–5+1)+5); |