Pseudorandom Number — Definition, Formula & Example
A pseudorandom number is a number produced by a fixed computer rule that only looks random. Start the rule from the same seed and you get exactly the same sequence again.
A pseudorandom number generator (PRNG) is a deterministic function on a finite state space, together with an output map. Starting from a seed , it produces the sequence . Because the state space is finite, the sequence is eventually periodic. A good generator has a long period, and its scaled outputs pass statistical tests for being independent draws from the uniform distribution on .
Key Formula
Where:
- = the n-th integer in the sequence, with 0 ≤ < m
- = the seed, the starting value you choose
- = the multiplier, a positive integer
- = the increment, a nonnegative integer
- = the modulus, which is the number of possible states
- = the output scaled to the interval [0, 1)
Worked Example
Problem: A linear congruential generator uses , , , and seed . Find the next three pseudorandom numbers, scaled to .
Step 1: Apply the rule to the seed. Divide by 16 and keep the remainder.
Step 2: Feed each output back into the rule.
Step 3: Divide each value by to get numbers in .
Answer: The integer sequence is 6, 1, 8, and the scaled outputs are 0.375, 0.0625, 0.5. Rerunning from seed 7 always gives these same values. This generator has , and is divisible by 2 and by 4. By the Hull–Dobell theorem, those conditions mean it cycles through all 16 states before it repeats.
Why It Matters
Monte Carlo simulation, bootstrap resampling in statistics, and randomized algorithms all rely on long streams of pseudorandom uniforms. Those uniforms are then transformed into other distributions. Reproducibility matters too: fixing the seed lets you or a reviewer rerun a simulation and get identical results.
Common Mistakes
Mistake: Treating any pseudorandom generator as safe for passwords, encryption keys, or lottery draws.
Correction: An attacker who sees a few outputs of a simple generator, such as a linear congruential generator, can often recover its parameters and predict every later value. For security, use a cryptographically secure generator. Reserve ordinary PRNGs for simulation and statistics.
