Syntax
RANDOM(seed)
Purpose
This function generates a 64-bit pseudo-random integer.
seedis an integer. Differentseedvalues generate different random number sequences.RANDOM()uses the MT19937 pseudo-random number generation algorithm, which has a very large random space. It will generate 219937 - 1 random elements before repeating the same sequence.
Examples
The following example shows how to use 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 shows how to use the result of RANDOM() 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, when RANDOM() is called with a variable as the parameter, the 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
