Syntax
RANDOM(seed)
Purpose
RANDOM() generates a pseudo-random number that is a 64-bit integer.
seedis an integer. The generated array of random numbers varies with the value ofseed.RANDOM()uses the MT19937 algorithm to generate pseudo-random numbers. This algorithm ensures a wide range for random numbers and generates a repeated array only after generating 219937 - 1 random elements.
Examples
The following example uses RANDOM() to generate random numbers.
obclient> SELECT RANDOM(4) FROM TABLE(GENERATOR(3));
+---------------------+
| RANDOM(4) |
+---------------------+
| 5267436225003336391 |
| -851690886662571060 |
| 1738617244330437274 |
+---------------------+
3 rows in set
The following example uses the result of the RANDOM() function as a random input for a distribution function.
obclient> SELECT UNIFORM(1, 100, RANDOM()) FROM TABLE(GENERATOR(4));
+-------------------------+
| UNIFORM(1,100,RANDOM()) |
+-------------------------+
| 73.61272325544115 |
| 40.25665028115364 |
| 66.83183914022183 |
| 70.22767627040167 |
+-------------------------+
4 rows in set
The following example shows a special scenario where the input parameter of RANDOM() is a variable and the value of seed is recalculated each time.
obclient> SELECT * FROM t1;
+------+
| c1 |
+------+
| 3 |
| 4 |
| 5 |
| 1 |
| 1 |
+------+
5 rows in set
obclient> SELECT t1.c1, RANDOM(t1.c1) FROM TABLE(GENERATOR(1)), t1;
+------+----------------------+
| c1 | RANDOM(t1.c1) |
+------+----------------------+
| 3 | 1084041170817055659 |
| 4 | 5267436225003336391 |
| 5 | 192483991702052534 |
| 1 | -6753783847308464280 |
| 1 | -6753783847308464280 |
+------+----------------------+
5 rows in set