Categories:

Data Generation Functions

UNIFORM

Generates a uniformly-distributed pseudo-random number in the inclusive range [min, max].

Syntax

UNIFORM( <min> , <max> , <gen> )
Copy

Arguments

min

A constant specifying the minimum value (inclusive) of the generated number.

max

A constant specifying the maximum value (inclusive) of the generated number.

gen

An expression that serves as a raw source of uniform random numbers, typically the RANDOM function. For more information, see the Data Generation Functions Usage Notes.

Returns

If either or both of min or max is a floating-point number, UNIFORM returns a floating-point number. If both min and max are integers, UNIFORM returns an integer.

Usage Notes

This function is related to, but different from, the RANDOM function. Both functions generate uniform distributions, but there are differences in the ranges of the values returned.

  • RANDOM generates pseudo-random 64-bit integers. It accepts an optional seed that allows sequences to be repeated.

  • UNIFORM generates random integer or floating-point numbers in the specified range.

Examples

SELECT uniform(1, 10, random()) FROM table(generator(rowCount => 5));

--------------------------+
 uniform(1, 10, random()) |
--------------------------+
 6                        |
 4                        |
 7                        |
 9                        |
 4                        |
--------------------------+
Copy
SELECT uniform(0::float, 1::float, random()) FROM table(generator(rowCount => 5));

---------------------------------------+
 uniform(0::float, 1::float, random()) |
---------------------------------------+
 0.2895427479                          |
 0.7178660941                          |
 0.6925603163                          |
 0.05914526824                         |
 0.8243151404                          |
---------------------------------------+
Copy
SELECT uniform(1, 10, 1234) FROM table(generator(rowCount => 5));

----------------------+
 uniform(1, 10, 1234) |
----------------------+
 7                    |
 7                    |
 7                    |
 7                    |
 7                    |
----------------------+
Copy