RNG Algorithm Comparator
Compare pseudo-random number generators (LCG, Mersenne Twister, xorshift) by their period, state space, and statistical quality
Try these examples:
Random Number Generator Comparator
Pseudo-random number generators (PRNGs) produce sequences that appear random but are deterministic. Quality depends on period, state space, and statistical properties.
Algorithm Types
Linear Congruential Generator (LCG)
The simplest PRNG, defined by:
Fast and simple, with period up to (typically or ). Poor statistical quality in higher dimensions and not suitable for cryptography.
Here is a small one you can see whole: modulus with =
Successive pairs of an LCG over one full period
Each dot is a pair of successive outputs , divided by . Over one period the generator produces every value from 0 to once, so these are all the pairs it can ever produce, and they do not fill the square: they lie on a few parallel lines. Knuth's spectral test measures how far apart those lines are: =
Mersenne Twister
A widely-used PRNG with period (MT19937 variant), a large state space (624 words), and strong statistical properties. Still not cryptographically secure.
Xorshift
A family of PRNGs based on XOR and shift operations. Period up to (xorshift128+), small state (2--4 words), very fast, and good statistical properties. Not cryptographically secure.
Configure Your Algorithm
Seed value:
Period (in bits):
State size (in bytes):
Bits per output:
Algorithm Metrics
Period length:
State space:
Total outputs per cycle:
Memory and Performance
With state size
Memory footprint:
Time to exhaust (at 1M ops/sec):
This configuration is suitable for simulation and gaming but not for cryptographic applications. Use a CSPRNG (like ChaCha20) for security.
Understanding Period Length
The period is the sequence length before it repeats. Increase
Period:
Key considerations:
- Minimum period: Should far exceed the number of random values you need
- Birthday paradox: Collisions become likely after outputs
- State space: Must be large enough to hold all possible internal states
State Space vs. Output Space
Adjust
State space:
Output space:
Coverage ratio:
Excellent coverage -- each output value can be generated from multiple internal states.
Try it in Code
# PRNG algorithm comparison
period_bits = 32
state_size = 8
bits_per_output = 32
state_space_bits = state_size * 8
period_length = 2 ** period_bits
ops_per_sec = 1_000_000
years_to_exhaust = period_length / ops_per_sec / 31_536_000
print(f"Period: 2^{period_bits}")
print(f"State space: {state_space_bits} bits")
print(f"Output: {bits_per_output} bits/value")
print(f"Memory: {state_size} bytes")
print(f"Years to exhaust: {years_to_exhaust:.2e}")What to explore next
Algorithm Visualization with Flowcharts
Step through common algorithms with interactive flowcharts showing decision structures, loops, and execution paths
Big-O Complexity
Compare algorithm time complexities and see how different Big-O classes scale with input size
Big-O Complexity Quiz
Master algorithm complexity analysis by exploring time complexity, growth rates, and classifying algorithms into Big-O categories
Big O Notation Visualizer
Compare time complexities across different algorithm classes and understand asymptotic behavior
You might also like
RNG Test Suite
ExplorationApply statistical tests to evaluate random number generator quality using frequency tests, runs tests, and chi-square analysis
Algorithm Visualization with Flowcharts
ExplorationStep through common algorithms with interactive flowcharts showing decision structures, loops, and execution paths
Big O Notation Visualizer
ExplorationCompare time complexities across different algorithm classes and understand asymptotic behavior
Big-O Complexity
ExplorationCompare algorithm time complexities and see how different Big-O classes scale with input size