THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server RAND() Function

❮ SQL Server Functions

Example

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

SELECT RAND();
Try it Yourself »

Definition and Usage

The RAND() function returns a random number or a random number within a range.

The RAND() function will return a value between 0 (inclusive) and 1 (exclusive).

The RAND() function will return a completely random number if no seed is provided, and a repeatable sequence of random numbers if a seed value is used. 

Syntax

RAND(seed)

Parameter Values

Parameter Description
seed Optional. If specified, it produces a repeatable sequence of random numbers each time that seed value is provided

Technical Details

Works in: SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

More Examples

Example

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

SELECT RAND(6);
Try it Yourself »

Example

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

SELECT RAND()*(10-5)+5;
Try it Yourself »

Example

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

SELECT FLOOR(RAND()*(10-5+1)+5);
Try it Yourself »

❮ SQL Server Functions