Returns a pseudo-random float value from 0 through 1, exclusive.
Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.
Repetitive calls of RAND() with the same seed value return the same results.
For one 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 will always return the same sequence of numbers.
SELECT RAND(100), RAND(), RAND()
The following example produces four different random numbers that are generated by the RAND function.
DECLARE @counter smallint; SET @counter = 1; WHILE @counter < 5 BEGIN SELECT RAND() Random_Number SET @counter = @counter + 1 END; GO