DB2 Version 9.7 for Linux, UNIX, and Windows

RAND scalar function

Read syntax diagramSkip visual syntax diagram
>>-RAND--(--+------------+--)----------------------------------><
            '-expression-'      

The schema is SYSFUN.

The RAND function returns a floating point value between 0 and 1.

RAND is a non-deterministic function.

If an expression is specified, it is used as the seed value. The expression must be a built-in SMALLINT or INTEGER data type with a value between 0 and 2 147 483 647.

The data type of the result is double-precision floating point. If the argument is null, the result is the null value.

A specific seed value produces the same sequence of random numbers for a specific instance of a RAND function in a query each time the query is executed. If a seed value is not specified, a different sequence of random numbers is produced each time the query is executed within the same session. To produce a set of random numbers that varies from session to session, specify a random seed, such as one that is based on the current time.

The RAND scalar function does not guarantee the uniqueness of the random numbers. Use the GENERATE_UNIQUE scalar function to generate a series unique numbers.

The RAND function relies on the random number facilities of the host operating system. The random number facility of each host might vary in factors such as the number of potential distinct values and the quality of the randomness. For these reasons, the output of this function is not suitable as a source of randomness in a cryptographic system.