Declaration
UNIFORM(<min> , <max> , <gen>)
Description
This function returns an integer or floating-point number that follows a uniform distribution.
- The values of
minandmaxmust be scalar values that do not change during row iteration. For example, they can be constants or scalar functions. In PL, they can also be expressions such as@v1or1+@v3. - If both
minandmaxare integers, the output of theUNIFORM()function is an integer. Otherwise, the output is a floating-point number. genis a numeric generation function, typically generated using theRANDOM()function. If the input value is a constant, theUNIFORM()function also returns a constant value.
Examples
The following example evenly generates integers between 1 and 10.
obclient> SELECT v, COUNT(*) FROM (SELECT UNIFORM(1, 10, RANDOM()) v FROM TABLE(GENERATOR(1000000))) x GROUP BY v ORDER BY v;
+------+----------+
| v | count(*) |
+------+----------+
| 1 | 100738 |
| 2 | 100119 |
| 3 | 100223 |
| 4 | 99537 |
| 5 | 100125 |
| 6 | 100001 |
| 7 | 100275 |
| 8 | 99235 |
| 9 | 99837 |
| 10 | 99910 |
+------+----------+
10 rows in set
The following example shows that the return result type is related to the parameter type.
obclient> SELECT UNIFORM(0.0, 10, RANDOM()) FROM TABLE(GENERATOR(4)) ORDER BY 1;
+----------------------------+
| UNIFORM(0.0, 10, RANDOM()) |
+----------------------------+
| 2.3520877625884653 |
| 4.155845987385725 |
| 8.323930497420852 |
| 9.844002748532109 |
+----------------------------+
4 rows in set
obclient> SELECT UNIFORM(0, 10, RANDOM()) FROM TABLE(GENERATOR(4)) ORDER BY 1;
+--------------------------+
| UNIFORM(0, 10, RANDOM()) |
+--------------------------+
| 0 |
| 4 |
| 8 |
| 9 |
+--------------------------+
4 rows in set