random
random data generator
Repository
tvondra/random
https://github.com/tvondra/random
Source
random-2.0.0-dev.tar.gz
random-2.0.0-dev.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_random | 2.0.0 | FUNC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4790 | random | No | Yes | No | Yes | No | Yes | - |
| Related | permuteseq tsm_system_rows tsm_system_time pg_idkit sequential_uuids |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.0.0 | 1817161514 | pg_random | - |
| RPM | PIGSTY | 2.0.0 | 1817161514 | pg_random_$v | - |
| DEB | PIGSTY | 2.0.0 | 1817161514 | postgresql-$v-random | - |
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
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).
| Function | Description |
|---|---|
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);
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.