select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / MATHEMATICAL FUNCTIONS AND OPERATORS

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

Signatures & examples

random ( ) → double precision
Returns a random value in the range 0.0 <= x < 1.0
random() → 0.897124072839091
random ( min integer, max integer ) → integer
Returns a random value in the range min <= x <= max. For type numeric, the result will have the same number of fractional decimal digits as min or max, whichever has more.
random(1, 10) → 7
random(-0.499, 0.499) → 0.347
random ( min bigint, max bigint ) → bigint
Returns a random value in the range min <= x <= max. For type numeric, the result will have the same number of fractional decimal digits as min or max, whichever has more.
random(1, 10) → 7
random(-0.499, 0.499) → 0.347
random ( min numeric, max numeric ) → numeric
Returns a random value in the range min <= x <= max. For type numeric, the result will have the same number of fractional decimal digits as min or max, whichever has more.
random(1, 10) → 7
random(-0.499, 0.499) → 0.347
Version history 3
  1. PG 18 → 19changed
  2. PG 16 → 17changed
  3. PG 12 → 13changed

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source