random
random
pg_random : random data generator
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4790 | random
|
pg_random
|
2.0.0 |
FUNC
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r
|
No
|
Yes
|
No
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| See Also | permuteseq
tsm_system_rows
tsm_system_time
pg_idkit
sequential_uuids
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| 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 / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
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/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
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);Last updated on