Skip to content

RANDOM()

Return a random double precision number that falls within a range.

RANDOM([n1,n2])

If you specify parentheses only, the result falls between 0.0 and 1.0. Alternatively, you can specify the range, such as (5,10) or (100,1000).

Examples

premdb=# select random() from sys.const;
      random       
--------------------
 0.0963835035787144
(1 row)
premdb=# select random(),* from match order by 1;
       random        | seasonid |      matchday       | htid | atid | ftscore | htscore 
----------------------+----------+---------------------+------+------+---------+---------
 0.000131850332641704 |       16 | 2008-03-16 00:00:00 |   46 |   57 | 1-0     | 1-0
 0.000151282328515424 |        2 | 1993-12-29 00:00:00 |    2 |   84 | 3-0     |    
 0.000216605043567899 |       11 | 2003-01-29 00:00:00 |   24 |   51 | 2-2     | 0-1
 0.000481910348946516 |        1 | 1992-08-01 00:00:00 |    6 |   63 | 2-0     | -  
 0.000567176363097615 |        6 | 1998-03-31 00:00:00 |   47 |   77 | 0-0     | 0-0
...
yellowbrick=# select random(5,10) from sys.const;
     random      
------------------
 8.32123883983625
(1 row)
yellowbrick=# select random(10000.1,10001.2) from sys.const;
     random      
------------------
 10000.2421522765
(1 row)