Prefix-Deferred Array-Permutation PRNGs: Architecture and Verification of ra_core v2

Hamas A. Rahman (@hamzy-hams) · Published 2026-11-24 · Repository: ooalahhq/ra_prng (commit 3f41572)

1. Problem Statement: The Short-Prefix Regime

Parallel Monte Carlo simulations, procedural lookups, and hash-indexed stochastic kernels frequently require random streams addressed by a 2D coordinate (key, addr_hi) where each trajectory consumes only a small prefix of K 32-bit words (1 ≤ K << 255) before terminating via importance sampling, russian-roulette absorption, or boundary exit.

Conventional array-buffered generators pay an upfront O(N) block initialization cost (e.g., 256 words) regardless of whether the caller consumes 1 word or 255 words. Counter-based generators such as Philox4x32-10 avoid large state initialization, but evaluate 10 rounds of 32-bit multiplication and XOR-shift per 128-bit counter block (~10.6–11.0 cycles/byte at K=1 on scalar x86-64 hardware).

ra_core v2 addresses this trade-off through deferred prefix computation over a two-array 256-entry state (M[256] and L[256], 2 KiB L1-resident): initialization work scales strictly with the number of consumed words K up to the block boundary N - 1 = 255.

2. Architecture of ra_core v2

Promoted on 2026-11-04 as the canonical production configuration (Opsi_A3 + W2_D2_xag_opt + eng_v2_E2), ra_core v2 combines three mechanisms:

  1. 2D Cross-Pre-Mix (Opsi_A3): Maps 64-bit (key, addr_hi) coordinates through a coupled modular-addition and rotated-XOR pre-mix followed by two fmix32 avalanches, enforcing odd strides (| 1u) and a +1 index offset (i + 1) * step. This eliminates the zero fixed-point (M[0]=L[0]=0) and sequential addr_hi correlation defects found in earlier v1 prototypes.
  2. 2-Tap Causal Ramp-Up & Lag-2 Delayed Feedback (W2_D2_xag_opt): At K=1, evaluation touches only 2 state words (M[255] and M[1]); at K=2, 3 words. For longer prefixes, lag-2 delayed feedback exposes 2-step instruction-level parallelism (ILP) with in-place state coupling M[i+7] += L[d_use] and an O(1) 7-word guard fold at cycle boundaries.
  3. Stateful On-The-Fly Engine (eng_v2_E2): In ra_core_engine_t (3,520 bytes), draws K=1,2 execute purely in registers, draws K=3..254 advance in 2-step coupled pairs over an 8-word ring buffer (m_ring[8]), and full M, L array materialization is deferred until a stream crosses K ≥ 256.

3. Materialized-Buffer Throughput & Shootout Benchmarks

All throughput figures below write every generated word into an external materialized memory buffer followed by an optimization barrier and consumer checksum verification, preventing dead-code elimination (DCE). Measurements report the median of 7 (Stage 4) or 9 (Stage 6) pinned runs across two reference machines:

3.1 Production API Throughput Across Prefix Lengths (MiB/s)

API Mode K=1 (A / B) K=8 (A / B) K=64 (A / B) K=255 (A / B)
Direct Stateless (ra_core_default_into) 710.2 / 425.84 1,292.1 / 841.42 1,476.4 / 948.01 1,596.5 / 926.70
Stateful OTF Engine (eng_v2_E2) 570.2 / 352.36 934.0 / 524.46 1,059.1 / 567.00 1,103.3 / 583.21
8-Way AVX2 SIMD (ra_core_singleblock_x8_into) 1,329.2 / 883.12 5,648.4 / 3,714.07 9,851.4 / 5,944.28 10,687.9 / 6,180.36

3.2 Cross-Generator Shootout (Stage 6 Suite D, Median-of-9, 110/110 Bit-Exact A=B)

Generator Category K=1 MiB/s (A / B) K=1 cpb (B) K=255 MiB/s (A / B) K=255 cpb (B)
ra_core_v2 Direct 2D Addressable Array 716.65 / 461.09 4.12 1,435.75 / 917.39 2.07
ra_engine_v2 (eng_v2_E2) 2D Addressable Stateful 573.94 / 331.80 5.73 1,139.99 / 663.49 2.87
Philox4x32-10 2D Counter-Based 270.44 / 173.15 10.99 1,074.15 / 766.49 2.48
ChaCha8 (RFC 8439 KAT) 2D Stream Cipher 99.99 / 50.57 37.63 1,013.87 / 643.50 2.96
PCG32 1D Sequential Register 2,543.90 / 1,225.99 1.55 3,212.91 / 2,462.81 0.77
xoshiro256** 1D Sequential Register 646.81 / 431.74 4.41 3,560.00 / 2,455.20 0.78
WyRand 1D Sequential Register 2,681.20 / 1,426.94 1.33 4,592.86 / 2,721.27 0.70

Against its direct structural peer in 2D addressable generation (Philox4x32-10), ra_core_v2 Direct is 2.65× (A) / 2.66× (B) faster at K=1 and 1.34× (A) / 1.20× (B) faster at K=255 on scalar CPU execution (and 7.17× (A) / 9.12× (B) faster than scalar ChaCha8 at K=1).

3.3 End-to-End Monte Carlo Workloads (Median-of-9, Bit-Exact A=B)

4. Statistical Verification & Cross-Architecture Parity

5. Explicit Operating Boundaries & Retracted Legacy Claims

Engineering claims for ra_core v2 are strictly bounded by four negative results and methodological corrections documented in docs/ERRATA.md:

  1. Non-Cryptographic: ra_core v2 is designed for simulation and stochastic modeling. It must not be used as a CSPRNG.
  2. 1D Sequential Streams: When 2D (key, addr_hi) addressability is not needed, small-state 1D register generators (PCG32, xoshiro256**, WyRand) achieve 0.70–0.78 cpb at K=255 on Machine B and remain ~2.2×–3.2× faster than ra_core_v2.
  3. GPU Execution vs. Philox: On NVIDIA Blackwell (sm_120, RTX PRO 6000), ra_core v2 matches Philox4x32-10 at K=1 and 2D Ising (1.001×–1.010×) due to L1 shared-array overhead, and trails Philox at K=4 (0.777×) and K=8 (0.833×). Its primary advantage is on scalar and AVX2 CPU targets.
  4. Retraction of Early Pre-v2 Throughput Numbers: Two legacy numbers from September–October 2026 drafts (30,303.0 MB/s algebraic extrapolation from sub-nanosecond loops and 20,018.1 MB/s where passing raw_stream == NULL triggered compiler DCE) were formally retracted on 2026-11-02 and replaced by the materialized-buffer harness reported above.