Skip to content

random

pg_random : random data generator

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4790
random
pg_random
2.0.0
FUNC
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
permuteseq
tsm_system_rows
tsm_system_time
pg_idkit
sequential_uuids

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
2.0.0
18
17
16
15
14
pg_random-
RPM
PIGSTY
2.0.0
18
17
16
15
14
pg_random_$v-
DEB
PIGSTY
2.0.0
18
17
16
15
14
postgresql-$v-random-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el8.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el9.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el9.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el10.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
el10.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
d12.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
d12.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
d13.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
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
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
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
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u24.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u26.x86_64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
u26.aarch64
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PIGSTY 2.0.0
PackageVersionOSORGSIZEFile URL
pg_random_182.0.0el8.x86_64pigsty17.1 KiBpg_random_18-2.0.0-1PIGSTY.el8.x86_64.rpm
pg_random_182.0.0el8.aarch64pigsty16.9 KiBpg_random_18-2.0.0-1PIGSTY.el8.aarch64.rpm
pg_random_182.0.0el9.x86_64pigsty17.1 KiBpg_random_18-2.0.0-1PIGSTY.el9.x86_64.rpm
pg_random_182.0.0el9.aarch64pigsty16.7 KiBpg_random_18-2.0.0-1PIGSTY.el9.aarch64.rpm
pg_random_182.0.0el10.x86_64pigsty17.0 KiBpg_random_18-2.0.0-1PIGSTY.el10.x86_64.rpm
pg_random_182.0.0el10.aarch64pigsty16.9 KiBpg_random_18-2.0.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-random2.0.0d12.x86_64pigsty20.2 KiBpostgresql-18-random_2.0.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-random2.0.0d12.aarch64pigsty20.0 KiBpostgresql-18-random_2.0.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-random2.0.0d13.x86_64pigsty20.3 KiBpostgresql-18-random_2.0.0-1PIGSTY~trixie_amd64.deb
postgresql-18-random2.0.0d13.aarch64pigsty20.1 KiBpostgresql-18-random_2.0.0-1PIGSTY~trixie_arm64.deb
postgresql-18-random2.0.0u22.x86_64pigsty21.6 KiBpostgresql-18-random_2.0.0-1PIGSTY~jammy_amd64.deb
postgresql-18-random2.0.0u22.aarch64pigsty21.1 KiBpostgresql-18-random_2.0.0-1PIGSTY~jammy_arm64.deb
postgresql-18-random2.0.0u24.x86_64pigsty21.4 KiBpostgresql-18-random_2.0.0-1PIGSTY~noble_amd64.deb
postgresql-18-random2.0.0u24.aarch64pigsty21.1 KiBpostgresql-18-random_2.0.0-1PIGSTY~noble_arm64.deb
postgresql-18-random2.0.0u26.x86_64pigsty21.4 KiBpostgresql-18-random_2.0.0-1PIGSTY~resolute_amd64.deb
postgresql-18-random2.0.0u26.aarch64pigsty21.3 KiBpostgresql-18-random_2.0.0-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_random;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_random;		# install via package name, for the active PG version
pig install random;		# install by extension name, for the current active PG version

pig install random -v 18;   # install for PG 18
pig install random -v 17;   # install for PG 17
pig install random -v 16;   # install for PG 16
pig install random -v 15;   # install for PG 15
pig install random -v 14;   # install for PG 14

Create this extension with:

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 updated on