Skip to content

pcg_random

PCG pseudo-random number generator functions for PostgreSQL.

pgsql_pcg_random · PCG pseudo-random number generator functions for PostgreSQL.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100269pcg_randompgsql_pcg_random0.0.1FUNCApache-2.0C

Usage

Sources:

pcg_random version 0.0.1 exposes scalar, bounded, array, and bounded-array functions backed by a PCG generator. The optional seed argument selects a sequence; the implementation also mixes time and an address into each call.

Example

CREATE EXTENSION pcg_random;
SELECT pcg_random();
SELECT pcg_random_bound(100);
SELECT pcg_random_array(5);
SELECT pcg_random_bound_array(5, 100);

This is not a cryptographic random source. Pass a strictly positive bound and a small nonnegative array length; the C code does not adequately validate zero/negative bounds or lengths. More importantly, the install SQL declares nondeterministic functions IMMUTABLE, allowing planner constant folding and otherwise incorrect reuse. The source is from 2016 and has no current compatibility matrix; prefer maintained PostgreSQL randomness facilities.

Table reader