
“Random” sounds simple, but computers are machines built to do exactly the same thing every time. So how does a computer produce a random number at all? This guide explains true randomness, pseudo-randomness, the cryptographic kind that sits in between, and the small mistake that makes many random tools quietly unfair.
What makes a number random?
A sequence of numbers is random, in the everyday sense, when two things are true:
- Every possible value is equally likely (or follows the odds it is supposed to).
- The next value cannot be predicted from the ones before it.
A fair die meets both conditions. A list that goes 1, 2, 3, 4, 5, 6 has every value equally often, but it fails the second test completely. Good random number generators must pass both.
True random number generators
A true random number generator measures something unpredictable in the physical world: electrical noise in a circuit, tiny timing variations, radioactive decay, or atmospheric noise. Because the source is physical, there is no formula to predict the next value.
True randomness is excellent, but it has practical downsides. Physical sources can be slow, can drift as hardware heats up, and can carry small biases of their own. That is why they are usually not used directly.
Pseudo-random number generators
A pseudo-random number generator (PRNG) is a formula. It starts from a number called a seed and produces a long sequence that looks random, passes statistical tests, and is very fast. But it is completely determined by its seed: start from the same seed and you get the same sequence.
That is fine, and even useful, for video games and simulations where repeatable “randomness” helps with testing. It is not fine when the result must be unpredictable, such as a password or a contest draw. If someone can learn or guess the seed or the internal state, they can predict every future number.
In web browsers, the everyday PRNG is Math.random(). It is fast and good enough for animations and games, but it is not designed to be unpredictable, and browsers make no promises about its quality for security.
Cryptographically secure generators: the best of both
A cryptographically secure pseudo-random number generator (CSPRNG) combines the two ideas. It is seeded, and regularly reseeded, from true physical entropy collected by your operating system. Then it uses a cryptographic algorithm to stretch that entropy into as many numbers as needed. The design guarantees that even someone who sees a long run of outputs cannot predict the next one or work backward to earlier ones.
Every modern browser exposes one through crypto.getRandomValues(). It is the same source used to create encryption keys for secure connections. For all practical purposes, including fair draws, games, and classroom picks, its output is indistinguishable from true randomness.
All the tools on this site use crypto.getRandomValues() for every result. We even block the use of Math.random() in our code with an automatic check.
Turning random bits into a fair choice
A random generator produces raw bits, usually as a big number like a 32-bit integer between 0 and 4,294,967,295. Turning that into “pick one of 7 options” is where many tools go wrong.
The modulo mistake
The tempting shortcut is to take the remainder: random % 7. But 4,294,967,296 is not divisible by 7, so a few values are left over at the top, and they make the first few options very slightly more likely. This is called modulo bias.
With large random numbers, the bias is small, but it is real, and it grows with the number of options. For a tool that promises fairness, “slightly unfair” is still unfair.
The fix: rejection sampling
Rejection sampling removes the bias completely. The tool works out the largest multiple of 7 that fits in the random range, and if a random number lands above it, the tool throws it away and draws a new one. Every remaining value maps to the options in equal numbers, so each option gets exactly 1/7.
Rejections are rare, so this costs almost nothing in speed. Our tools use rejection sampling for wheels, dice, cards, pickers, and generators, and our test suite checks it with statistical tests on every build.
Shuffling correctly
Shuffling a list has its own classic mistake: swapping each item with any random position. That method produces some orders more often than others. The correct method, the Fisher–Yates shuffle, swaps each item only with an item at or after its own position. Combined with a fair random source, every possible order is equally likely. Our shuffle, team maker, card deck, and bingo caller all use Fisher–Yates.
How can you test randomness?
You cannot prove a generator is random by looking at a few results, because random results include streaks and repeats. Instead, statisticians compare many results with what fairness predicts.
A common test is the chi-square goodness-of-fit test. You count how often each outcome appears, compare the counts with the expected counts, and get a p-value. A very small p-value (say, below 0.01) means the spread would be unusual for a fair generator. Note the word unusual: even a perfect generator will produce a small p-value about 1% of the time.
Every tool on this site has a Test the fairness yourself box that runs 10,000 draws on your device and reports exactly this test. Run it several times and you will see p-values scattered between 0 and 1, which is what fairness looks like.
Is “computer random” good enough for a raffle?
For school raffles, giveaways, classroom picks, and games, a cryptographic generator is more than good enough, and it is fairer than drawing paper slips from a hat, which can stick together or sit at the top.
For lotteries and prize promotions run for money, the law in many places requires certified equipment or audited processes. Use the official process required where you are. See how to run a fair raffle for practical advice.
Summary
- True randomness comes from physical noise; pseudo-randomness comes from a formula.
- Cryptographic generators combine both and are unpredictable in practice.
crypto.getRandomValues()is the right source in a browser;Math.random()is not for fair draws.- Modulo bias makes naive tools unfair; rejection sampling fixes it.
- Fisher–Yates is the correct way to shuffle.
- Fairness is tested with many results, not a few.
Try it with the random number generator: pick a small range and press Run 10,000.


