Pseudorandomness — how a computer rolls dice
About this app
A random number generator is a fixed rule: same seed, same sequence, and eventually the loop closes. Middle-square, a linear congruential generator with freely adjustable parameters, RANDU, a shift register and xorshift side by side — good ones and deliberately bad ones. Four views reveal what a list of numbers hides: the rule with values plugged in, the cycle as a rho shape, the scatter of consecutive pairs plus a rotatable cloud of triples (RANDU collapses into 15 planes), and a histogram.
Randomness from a formula
A pseudorandom number generator (PRNG) is a fixed rule: the current state determines the next. The same seed yields exactly the same sequence. Because there are only finitely many states, every sequence eventually loops; a lead-in is followed by a cycle, the ρ shape. A good generator has a very long period and no structure that shows up in practice. A linear congruential generator x ← (a·x + c) mod m reaches full period by the Hull–Dobell theorem if c and m are coprime, a − 1 is divisible by every prime factor of m, and by 4 if 4 divides m.
What the app shows
Six generators are available: von Neumann’s middle-square, an LCG with freely chosen a, c and m, IBM’s RANDU, a linear feedback shift register (LFSR), Xorshift32 and the browser’s Math.random(). Four views reveal what a list of numbers hides: the rule with values filled in, the cycle as a ρ shape, a scatter plot of consecutive pairs or a rotatable 3D cloud of triples, and a histogram. Key figures show lead-in, period and the Hull–Dobell check.
Try it yourself
Start middle-square and watch the sequence collapse to 0 or a tiny cycle within a few dozen steps. Load the LCG preset “stripes”: the histogram is perfectly flat, yet all pairs lie on a few lines. Choose RANDU, switch to 3D triples and rotate the cloud into the plane view: all points lie on 15 planes. None of these generators is fit for cryptography; that needs a cryptographically secure generator such as crypto.getRandomValues().
Frequently asked questions
- What is a pseudorandom number generator?
- A pseudorandom number generator uses a fixed rule to produce a sequence of numbers that looks random. The same seed always yields the same sequence. That is useful for simulations because results are reproducible.
- What is a linear congruential generator?
- A linear congruential generator computes the next number as x ← (a·x + c) mod m. It is very fast, but its quality depends heavily on a, c and m. Even with full period, consecutive values viewed as points lie on a few lines or planes.
- Why is RANDU a bad random number generator?
- RANDU is an LCG from the 1960s with a = 65539 and m = 2³¹. Taking three consecutive values as a point in space, all points lie on just 15 planes. Simulations using such triples were distorted for years.
- Which generators can I compare in the app?
- Middle-square, an LCG with custom parameters and presets, RANDU, an LFSR with selectable taps, Xorshift32 and Math.random(). For each, the app shows the cycle, scatter plot and distribution.
Subject: Cryptography
More from Cryptography
- The Nonce Lottery
- Hashing & collisions
- SHA-256 in slow motion (8-bit model)
- Cracking a Substitution Cipher
- Encrypt and Sign with Two Keys
A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps