DoesWhatAnswersSlangEmojisCalculatorsTriviaPlayBlog

Trivia Questions and Weird Facts

Math

How Does a Random Number Generator Work?

Short answerA random number generator produces numbers with no predictable pattern. A true one uses physical noise like radioactive decay or dice. A pseudorandom one uses a formula and a seed, so the numbers look random but are fully determined. Most software uses the pseudorandom kind, which is fast and good enough for games and simulations.

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.

StepCalculationResult
1(5 x 7 + 3) mod 166
2(5 x 6 + 3) mod 161
3(5 x 1 + 3) mod 168

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

Keep going