Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

RAND

Example

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();

Definition and Usage

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

Syntax

RAND(seed)

Parameter Values

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.

Technical Details

Works in:

SQL Server (beginning from 2008), Azure SQL Database, Azure SQL Data Warehouse

More Examples

Example

Generate 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 between 5 and 10, inclusive.

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