RANDOM
Returns a pseudo-random unsigned value greater than 0 and less than 1 of type DOUBLE PRECISION
.
Syntax
RANDOM()
Return Types
DOUBLE PRECISION
Example
The example below demonstrates using RANDOM
without any other numeric functions. This generates a DOUBLE PRECISION
value less than 1:
SELECT RANDOM()
Returns: 0.8544004706537051
Example–using RANDOM for range of values
To create a random integer number between two values, you can use RANDOM
with the FLOOR
function as demonstrated below. a
is the lesser value and b
is the greater value.
SELECT
FLOOR(RANDOM() * (b - a + 1)) + a;
For example, the formula below generates a random integer between 50 and 100:
SELECT
FLOOR(RANDOM() * (100 - 50 + 1)) + 50;
Returns: 61