PostgreSQL's pseudo-random generator, ported from src/common/pg_prng.c.
Ported rather than substituted for java.util.Random because it makes
random() TESTABLE: SETSEED(0.5) followed by a fixed number of
random() calls produces one exact sequence, so the differential
against a real PostgreSQL is bit-for-bit rather than a smoke test
that can only check the range.
xoroshiro128** with a splitmix64 seeder. All arithmetic is on Java longs, which are the same 64 bits as PostgreSQL's uint64 -- only the comparisons and the shift right differ, so every right shift here is the UNSIGNED one.
PostgreSQL's pseudo-random generator, ported from src/common/pg_prng.c. Ported rather than substituted for java.util.Random because it makes `random()` TESTABLE: `SETSEED(0.5)` followed by a fixed number of `random()` calls produces one exact sequence, so the differential against a real PostgreSQL is bit-for-bit rather than a smoke test that can only check the range. xoroshiro128** with a splitmix64 seeder. All arithmetic is on Java longs, which are the same 64 bits as PostgreSQL's uint64 -- only the comparisons and the shift right differ, so every right shift here is the UNSIGNED one.
(draw-double! cell)Advance cell and return the next double in [0,1).
Advance `cell` and return the next double in [0,1).
(fseed-state fseed)pg_prng_fseed: scale the [-1,1] argument by 2^52-1 and truncate toward zero, exactly as the C cast to int64 does.
pg_prng_fseed: scale the [-1,1] argument by 2^52-1 and truncate toward zero, exactly as the C cast to int64 does.
(make-session-state)A per-session PRNG cell. PostgreSQL seeds from the clock and the backend PID until SETSEED is called.
A per-session PRNG cell. PostgreSQL seeds from the clock and the backend PID until SETSEED is called.
(next-double state)pg_prng_double: the top 52 bits scaled into [0,1). Returns
[value new-state].
pg_prng_double: the top 52 bits scaled into [0,1). Returns `[value new-state]`.
(next-u64 [s0 s1])One xoroshiro128** step. Returns [value new-state].
One xoroshiro128** step. Returns `[value new-state]`.
(seed-state seed)pg_prng_seed: two splitmix64 draws from the seed. The all-zero state is invalid for xoroshiro, and PostgreSQL substitutes a fixed pair.
pg_prng_seed: two splitmix64 draws from the seed. The all-zero state is invalid for xoroshiro, and PostgreSQL substitutes a fixed pair.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |