random()

Returns a random value in the range 0.0 <= x < 1.0

Signature

random ( ) → double precision
random ( min integer, max integer ) → integer
random ( min bigint, max bigint ) → bigint
random ( min numeric, max numeric ) → numeric

In other engines

PostgreSQLrandom
MySQLRAND()
SQL ServerRAND(), which is per-statement, or NEWID() per row
OracleDBMS_RANDOM.VALUE
SQLiterandom(), which returns a signed 64-bit integer

SQL Server's RAND() is evaluated once per statement, so ORDER BY RAND() does not shuffle — ORDER BY NEWID() is the idiom. SQLite's random() is not in [0,1) like everyone else's.

Want to run this against your own PostgreSQL server from an iPhone, iPad or Mac? These are ours — every connection goes straight from the device to your database, with no account and no server of ours in between.

Signature and description adapted from the PostgreSQL manual, used under the PostgreSQL License. PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada. This page is not affiliated with the PostgreSQL Global Development Group.