Export (0) Print
Expand All
ABS
ALL
AND
ANY
AVG
bit
COS
COT
DAY
EXP
GO
IN
LEN
LOG
MAX
MIN
NOT
OR
PI
SET
SIN
STR
SUM
TAN
USE
VAR
Expand Minimize

RAND

SQL Server 2000

  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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft