Transact-SQL Reference

RAND

Returns a random float value from 0 through 1.

Syntax

RAND ( [ seed ] )

Arguments

seed

Is an integer expression (tinyint, smallint, or int) that gives the seed or start value.

Return Types

float

Remarks

Repetitive invocations of RAND() in a single query will produce the same value.

Examples

This example produces four different random numbers generated with the RAND function.

DECLARE @counter smallint
SET @counter = 1
WHILE @counter < 5
   BEGIN
      SELECT RAND(@counter) Random_Number
      SET NOCOUNT ON
      SET @counter = @counter + 1
      SET NOCOUNT OFF
   END
GO

Here is the result set:

Random_Number                                         
------------------- 
0.71359199321292355

(1 row(s) affected)

Random_Number                                         
------------------- 
0.7136106261841817

(1 row(s) affected)

Random_Number                                         
------------------- 
0.71362925915543995

(1 row(s) affected)

Random_Number                                         
------------------- 
0.7136478921266981

(1 row(s) affected)

See Also

Mathematical Functions