PostgreSQL 17.9
RANDOM([min, max])- [ ]optional part
- min
- Lower bound, inclusiveinteger | bigint | numericOptional
- max
- Upper bound, inclusiveinteger | bigint | numericOptional
Return value
Without arguments, double precision from 0 inclusive to 1 exclusive; with min and max, a number of the same type from min to max inclusive
Examples
Random number from 0 to 1
PostgreSQL 17.9
SELECT RANDOM();Random integer from 1 to 6
PostgreSQL 17.9
SELECT RANDOM(1, 6);Random table row
PostgreSQL 17.9
SELECT member_name
FROM FamilyMembers
ORDER BY RANDOM()
LIMIT 1;Details
To get a repeatable sequence, call SETSEED before RANDOM.