RAND (T-SQL)

Returns a random float value between 0 and 1.

Syntax

RAND([seed])

Arguments
seed
Is an integer expression (tinyint, smallint, or int) giving the seed or starting value.
Return Types

float

Examples

This example uses a variable to produce five different random numbers generated with the RAND function.

DECLARE @counter smallint

SET @counter = 1

WHILE @counter < 5

    BEGIN

        SELECT RAND(@counter)

        SET NOCOUNT ON

        SET @counter = @counter + 1

        SET NOCOUNT OFF

    END

GO

  

Here is the result set:

(1 row(s) affected)

                         

------------------------

0.00125125888851588     

(1 row(s) affected)

                         

------------------------

0.00137333292641987     

(1 row(s) affected)

                         

------------------------

0.00146488845484787     

(1 row(s) affected)

                         

------------------------

0.00155644398327586     

(1 row(s) affected)

                         

See Also

Mathematical Functions

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.