Syntax
UNIFORM(<min> , <max> , <gen>)
Purpose
The UNIFORM() function returns an integer or a float value that follows a uniform distribution.
minandmaxmust be scalar values that do not change with each row iteration. For example, constants and scalar functions. In PL, they can also be expressions like@v1or1+@v3.- In Oracle mode, regardless of whether
minandmaxare integers, they are treated asNUMBERtypes, and the output of theUNIFORM()function is a float. If you want to generate an integer, you can use theFLOOR()function in combination withUNIFORM(). genis a numerical generation function, typically using theRANDOM()function. If the input value is a constant, theUNIFORM()function will return a fixed value.
Examples
The following example shows how the result type of the UNIFORM() function depends on the types of its parameters.
obclient> SELECT UNIFORM(0.0, 10, RANDOM()) FROM TABLE(GENERATOR(4)) ORDER BY 1;
+--------------------------+
| UNIFORM(0.0,10,RANDOM()) |
+--------------------------+
| .8657087411722835 |
| 1.0922542185892958 |
| 1.1803956370514672 |
| 5.613282729140028 |
+--------------------------+
4 rows in set
obclient> SELECT UNIFORM(0, 10, RANDOM()) FROM TABLE(GENERATOR(4)) ORDER BY 1;
+------------------------+
| UNIFORM(0,10,RANDOM()) |
+------------------------+
| 2.6761305377880125 |
| 3.0277418674828116 |
| 5.170644071608517 |
| 5.805950943815582 |
+------------------------+
4 rows in set
