How Does a Random Number Generator Work?
People usually mean one of two things here: the mathematical idea of randomness, or the specific tool (a calculator, a function, a website) that spits out numbers for them. Both come down to the same core question: can you predict the next number? If not, it is random enough.
What Is a Random Number Generator?
A random number generator, or RNG, is any process that returns numbers with no usable pattern. True random generators sample a physical source, like atmospheric noise, radioactive decay, or a coin flip. Pseudorandom generators (PRNGs) run a deterministic formula from a starting value called a seed. Give the same seed twice and you get the same sequence, which is a feature for testing and a bug if you wanted surprise.
How Does the Formula Work?
A common PRNG is the linear congruential generator. It takes the previous number, multiplies it, adds a constant, then takes the remainder after dividing by a modulus. In plain words: scramble the last number, chop it down to size, repeat. The formula is X next = (a times X current + c) mod m, where a, c, and m are fixed constants you pick in advance.
Worked Example
Pick a = 5, c = 3, m = 16, and a seed of 7.
| Step | Calculation | Result |
|---|---|---|
| 1 | (5 x 7 + 3) mod 16 | 6 |
| 2 | (5 x 6 + 3) mod 16 | 1 |
| 3 | (5 x 1 + 3) mod 16 | 8 |
The sequence 6, 1, 8 looks scattered, but it repeats eventually and anyone with the formula and seed can rebuild it. That is why serious cryptography uses hardware noise, not a simple formula.
Is a Random Number Generator Actually Random?
Honest answer: the software kind is not truly random, just hard to predict. The site calculator lets you generate numbers in a range, and it is great for quick picks, classroom demos, and settling who buys coffee. For passwords and encryption, use a generator built on a secure random source.
A fun fact to file away: in 2012, security researchers found that some online poker deals were predictable because the shuffle relied on a weak seed, which is the exact failure mode the formula above warns about.
Do the math: open the random number generator