Random Number Generator Guide: How Randomness Works
Quick answer
Understand how random number generators work, true vs pseudo-randomness, and applications in gaming, statistics, and security. This guide answers that in plain language, with the practical steps first and the background afterwards.
Key facts
| What this article covers | Understand how random number generators work, true vs pseudo-randomness, and applications in gaming, statistics, and security. |
|---|---|
| Topic | Math |
| Reading time | 10 min read |
| Published | April 12, 2026 |
| Written by | The SimpleCounter editorial team, who build and use these counting tools. |
| Cost of the tools mentioned | Free, with no account required. |
Picking a raffle winner, shuffling a playlist, assigning people to test groups, and generating an encryption key all ask for a random number, but they do not all need the same kind of randomness. The difference between a generator that looks random and one that cannot be predicted is the difference between a fair prize draw and a broken password.
Pseudo-Random Generators
Most software randomness is pseudo-random. An algorithm starts from a seed value and produces a sequence that passes statistical tests for randomness while being entirely determined by that seed. Feed in the same seed and you get the same sequence every time. That reproducibility is a feature in simulation and testing, where you want to rerun an experiment exactly, and a serious liability in security, where predictability is the whole attack.
The classic method is a linear congruential generator, which multiplies, adds, and takes a remainder at each step. Modern languages mostly use better algorithms such as Mersenne Twister or xoshiro variants, which have far longer periods before the sequence repeats and much better distribution properties.
Cryptographically Secure Generators
When the number needs to resist an attacker, use a cryptographically secure generator. These draw entropy from physical unpredictability the operating system collects: timing jitter, interrupt patterns, hardware noise sources. In a browser, that means crypto.getRandomValues rather than Math.random. In Python it means the secrets module rather than random. The practical rule is simple: anything that protects something, such as a token, password, session identifier, or key, needs the secure generator.
True Random Sources
Hardware random number generators sample physical processes that are genuinely unpredictable, including thermal noise in a resistor, avalanche noise in a diode, and radioactive decay timing. Several public services offer atmospheric noise as a randomness source for lotteries and audits. True randomness is slower to produce than algorithmic output, so a common design uses a hardware source to seed a fast secure algorithm rather than drawing every byte from the hardware.
Getting a Range Without Bias
Turning a random integer into a number from 1 to 6 by taking a remainder introduces modulo bias whenever the range does not divide the generator output evenly. Some values become slightly more likely than others. The correct approach is rejection sampling: discard results that fall in the leftover partial block and draw again. Most standard library range functions already do this, which is another reason to prefer them over hand-rolled remainder arithmetic.
The same principle applies to shuffling. The Fisher-Yates algorithm, which walks the list backwards swapping each element with a random earlier position, produces every ordering with equal probability. Sorting a list by a random comparison function does not, and it is a surprisingly common bug in prize draws.
What Randomness Does Not Look Like
People are poor judges of random sequences. Genuine randomness produces clumps: in 20 coin flips, a run of four or five identical results is common, not suspicious. Conversely a sequence with no runs at all looks random to the eye but is statistically improbable. This is why music shuffle features often deliberately avoid true randomness, spacing out songs by the same artist because listeners complain that real randomness sounds broken.
Each draw is also independent. A die that has shown six three times running is no less likely to show six again. Expecting a correction is the gambler fallacy, and no random number generator owes you a balance.
Practical Uses and the Right Tool
- Prize draws and classroom picks: a simple range generator is fine, and showing the range and the result is enough for transparency.
- A/B testing and sampling: seed the generator and record the seed so the assignment can be reproduced and audited.
- Monte Carlo simulation: use a high-quality pseudo-random generator with a long period, and run enough iterations that the estimate stabilises.
- Passwords and tokens: use a cryptographically secure source and enough length. A 16-character password from a 90-character set has far more resistance than a clever short one.
Testing a Generator
Basic checks go a long way. Generate a large sample and count how often each outcome appears; a fair six-sided draw over 60,000 rolls should give each face close to 10,000, within a few hundred. Look at pair frequencies to catch correlation between consecutive values. Formal test suites such as the diehard tests and TestU01 exist for anyone building a generator, though for ordinary work using a well-reviewed library is a better use of effort than testing your own.
Fairness in Public Draws
If a draw needs to be trusted by others, publish the method, the entry list, and the seed or source before drawing, then show the result. Commit-and-reveal, where you publish a hash of the seed in advance and the seed afterwards, lets anyone verify the outcome was not chosen after the fact. That transparency matters more than which algorithm you picked.
Generate Random Numbers Free
The random number generator on SimpleCounter lets you set any range, draw single or multiple values, and choose whether repeats are allowed, which covers raffles, team picks, and dice rolls. It runs in your browser, so nothing about your draw is sent anywhere.
How this page relates to the rest of the site
- Type of
- Guide
- Related tools
- Calculators and converters
- Published by
- SimpleCounter
Related articles
Fraction Calculator Guide: Operations with Fractions
Master fraction arithmetic with step-by-step examples.
Average Calculator: Mean, Median, Mode Explained
Learn the differences between mean, median, mode, and range with examples.
Square Root Calculator Guide: Perfect Squares
Learn about square roots, perfect squares, and cube roots.
Get Counting Tips in Your Inbox
Subscribe for productivity tips, counting techniques, and new feature updates.
No spam, unsubscribe anytime.