Generate a random decimal number without specifying a seed, resulting in a number that is greater than or equal to 0 and less than 1.
| SELECT RAND(); |
The RAND() function generates a random number within the range from 0 (inclusive) to 1 (exclusive).
| RAND(seed) |
|
Parameter |
Description |
|
seed |
If a seed is specified, the RAND() function produces a repeatable sequence of random numbers. Without specifying a seed, it generates entirely random numbers. |
|
Works in: |
SQL Server (beginning from 2008), Azure SQL Database, Azure SQL Data Warehouse |
Generate 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 between 5 and 10, inclusive.
| SELECT FLOOR(RAND()*(10–5+1)+5); |