Risk & Modeling

Pseudorandom Number Generator (PRNG)

TL;DR

A PRNG produces sequences of numbers that appear random but are fully deterministic — controlled by an initial seed value. This gives Retirement Lab the best of both worlds: realistic randomness for simulation, plus perfect reproducibility so identical inputs always produce identical results.

A pseudorandom number generator (PRNG) is an algorithm that produces a sequence of numbers approximating the properties of truly random numbers, starting from an initial value called a seed. Unlike hardware random number generators, a PRNG is entirely deterministic — given the same seed, it produces the exact same sequence every time.

How It Works

Retirement Lab uses the seedrandom library for its PRNG, which implements a high-quality algorithm (Alea) with a period long enough to prevent repetition within any practical simulation.

The pipeline:

  1. A seed is set at the start of each simulation run
  2. The PRNG generates uniform random numbers in [0, 1)
  3. These feed into the Marsaglia Polar Method to produce normally distributed values
  4. Further transformations produce Student-t and skewed distributions

All randomness in the engine flows through the PRNG — there are no calls to Math.random(). This is a strict design constraint that ensures every simulation is reproducible.

Why It Matters for Retirement Planning

Deterministic simulation matters for three reasons:

  1. Reproducibility: the same inputs always produce the same results, so you can revisit and verify past simulations
  2. Fair comparisons: when testing two different withdrawal strategies, both use the same market scenarios (same seed), isolating the effect of the strategy change
  3. Validation: the engine can be verified for correctness — if results change unexpectedly, it indicates a code change, not random variation

This is why Retirement Lab's engine is designed to be pure (no side effects, no DOM access, no Math.random()) — a constraint that also enables future Web Worker offloading for parallel simulation runs.

Frequently Asked Questions

Why does Retirement Lab use a seeded PRNG instead of true random numbers?
Determinism. A seeded PRNG guarantees that identical inputs produce identical results, making simulations reproducible and verifiable. If you run the same scenario twice with the same seed, you get exactly the same 10,000 iterations. This is essential for debugging, validation, and comparing scenarios where only one variable changes.
Does the seed value affect the quality of the simulation?
No. Any seed produces a statistically equivalent stream of random numbers. The seed only determines which specific sequence is generated. Different seeds give different individual iterations, but the aggregate statistics (success rate, percentile bands) converge to the same values as the number of iterations increases.