Function Reference

RANDOM

MySQL equivalent:

Returns a random number from 0 to 1 or from min to max.

PostgreSQL 17.9
RANDOM([min, max])
  • [ ]optional part
min
Lower bound, inclusive
integer | bigint | numericOptional
max
Upper bound, inclusive
integer | 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
0.579777939257887

Random integer from 1 to 6

PostgreSQL 17.9
SELECT RANDOM(1, 6);
random
4

Random table row

PostgreSQL 17.9
SELECT member_name
FROM FamilyMembers
ORDER BY RANDOM()
LIMIT 1;
member_name
Headley Quincey

Details

To get a repeatable sequence, call SETSEED before RANDOM.

See also