RAND (SYSIBM schema) scalar function

The RAND function returns a floating point value between 0 and 1. RAND is a non-deterministic function.

Read syntax diagramSkip visual syntax diagramRAND(expression)

The schema is SYSIBM.

expression
The expression represents the value of a seed which is used to initialize the random number generator. The expression must return a built-in character string, or numeric value. In a Unicode database, the expression can also return a graphic string, in which case it is first converted to a character string before the function is evaluated. If the returned value is not a INTEGER, it is cast to INTEGER before evaluating the function. The value must be between 0 and 2,147,483,647.

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. The seed value is used only for the first invocation of an instance of the RAND function within a statement. 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; for example, 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.

Result

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