random

random data generator

Overview

PackageVersionCategoryLicenseLanguage
pg_random2.0.0FUNCPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4790randomNoYesNoYesNoYes-
Relatedpermuteseq tsm_system_rows tsm_system_time pg_idkit sequential_uuids

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY2.0.01817161514pg_random-
RPMPIGSTY2.0.01817161514pg_random_$v-
DEBPIGSTY2.0.01817161514postgresql-$v-random-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u22.x86_64
u22.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u24.x86_64
u24.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0

Build

You can build the RPM / DEB packages for pg_random using pig build:

pig build pkg pg_random         # build RPM / DEB packages

Install

You can install pg_random directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_random;          # Install for current active PG version
pig ext install -y pg_random -v 18  # PG 18
pig ext install -y pg_random -v 17  # PG 17
pig ext install -y pg_random -v 16  # PG 16
pig ext install -y pg_random -v 15  # PG 15
pig ext install -y pg_random -v 14  # PG 14
dnf install -y pg_random_18       # PG 18
dnf install -y pg_random_17       # PG 17
dnf install -y pg_random_16       # PG 16
dnf install -y pg_random_15       # PG 15
dnf install -y pg_random_14       # PG 14
apt install -y postgresql-18-random   # PG 18
apt install -y postgresql-17-random   # PG 17
apt install -y postgresql-16-random   # PG 16
apt install -y postgresql-15-random   # PG 15
apt install -y postgresql-14-random   # PG 14

Create Extension:

CREATE EXTENSION random;

Usage

random: reproducible random data generators for PostgreSQL

Provides functions to generate random values for various data types with reproducible output controlled by a seed.

CREATE EXTENSION random;

Functions

All functions accept seed (for reproducibility) and nvalues (number of distinct values).

FunctionDescription
random_string(seed, nvalues, min_length, max_length)Random ASCII string
random_bytea(seed, nvalues, min_length, max_length)Random bytea
random_int(seed, nvalues, min_value, max_value)Random 32-bit integer
random_bigint(seed, nvalues, min_value, max_value)Random 64-bit integer
random_real(seed, nvalues, min_value, max_value)Random 32-bit float
random_double_precision(seed, nvalues, min_value, max_value)Random 64-bit float
random_inet(seed, nvalues)Random INET address (/32 mask)
random_cnet(seed, nvalues)Random CIDR with masks 8/16/24/32
random_cnet2(seed, nvalues)Random CIDR with equal fraction per mask length
random_macaddr(seed, nvalues)Random 6-byte MAC address
random_macaddr8(seed, nvalues)Random 8-byte MAC address

Examples

-- Generate reproducible random integers
SELECT random_int(42, 100, 1, 1000) FROM generate_series(1, 10);

-- Random strings of length 5-10
SELECT random_string(42, 1000, 5, 10) FROM generate_series(1, 5);

-- Random IP addresses
SELECT random_inet(42, 256) FROM generate_series(1, 5);

Last Modified 2026-03-12: add pg extension catalog (95749bf)