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

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