RAND

The RAND function returns a random floating-point value between 0 and 1. An argument can be specified as an optional seed value.



numeric-expression
If numeric-expression is specified, it is used as the seed value. The argument must be an expression that returns a value of a built-in integer data type (SMALLINT or INTEGER). The value must be between 0 and 2,147,483,646.

The argument can also be a character string or graphic string data type. The string input is implicitly cast to a numeric value of DECFLOAT(34) and then assigned to an INTEGER value.

The result of the function is a double precision floating-point number.

A specific seed value, other than zero, will produce 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. RAND(0) is processed the same as RAND().

The RAND function is a non-deterministic function.

Example:

The following example assigns a random number for the column EMPL_ID in the table EMPLOYEE.


INSERT INTO EMPL_COMP (EMPL_ID, EMPL_NAME) VALUES(RANDOM(),'KANE');

The above example assigns a random value for the EMPL_ID column for the employee KANE as shown below.


EMPL_ID, EMPL_NAME, COMPANY, LOCATION, UPDATED_TS
1 , AKHIL , TIMBER INC. , NY , 2019-11-26 05:39:59.454707
2 , ELICA , STANLEY INC. , TX , 
3 , SMITH , CHROME INC. , WA , 
1919574970 , KANE ,  ,  ,