Syntax
UNIFORM(<min> , <max> , <gen>)
Purpose
UNIFORM() returns a uniformly distributed integer or floating-point number.
minandmaxmust be scalar values that do not change with row iteration. For example, they can be constants and scalar functions. In PL, they can also be@v1and1+@v3.- In Oracle mode,
minandmaxare treated as theNUMBERtype, regardless of whether they are integers. The output of theUNIFORM()function is a floating-point number. To generate an integer, you can useUNIFORM()together with theFLOOR()function. genis a numeric value generation function. Generally, theRANDOM()function is used. If the input value is a constant,UNIFORM()returns a fixed value.
Examples
The following example shows that the data type of the result returned by UNIFORM() is related with the type of its arguments.
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