Topic last updated -- July 2003
Returns a random float value from 0 through 1.
Syntax
RAND ( [ seed ] )
Arguments
seed
Is an integer expression (tinyint, smallint, or int) that specifies the seed value. If seed is not specified, Microsoft® SQL Server™ 2000 assigns a seed value at random. For a given seed value, the result returned is always the same.
Return Types
float
Remarks
Repetitive calls of RAND() with the same seed value in a single query return the same results.
For a connection, if RAND() is called with a specified seed value, all subsequent calls of RAND() produce results based on the seeded RAND() call. For example, the following query always returns the same sequence of numbers.
SELECT RAND(100), RAND(), RAND()
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() Random_Number
SET NOCOUNT ON
SET @counter = @counter + 1
SET NOCOUNT OFF
END
GO
See Also
Mathematical Functions