Skip to main content

Guides

Is a Random Number Generator Fair?

A random number generator is fair when every allowed number has the same chance of coming up, and when one result gives no clue about the next. That sounds simple, but there are a few common ways for software to get it slightly wrong, even when the underlying source of randomness is good.

This guide explains how computers produce random numbers, where bias creeps in, and how our generator avoids it. It also shows how you can test fairness yourself, and what fair cannot mean: no generator can predict or influence a lottery draw, and nothing improves its odds.

8 min readPublished 2026-11-02

Is it fair? Test it

Draw 10,000 numbers from 1–10 with the same random source the generator uses and count how often each comes up. Each should land near 1,000.

PRNG and CSPRNG: two kinds of randomness

Most software uses a pseudo-random number generator, or PRNG. It is a formula that turns a starting value, the seed, into a long sequence of numbers that look random. Given the same seed it always produces the same sequence, which is useful for games and simulations but means the output can in principle be predicted.

A cryptographically secure generator, or CSPRNG, is designed so that its output cannot be predicted in practice, even by someone who has seen earlier values. It is seeded from unpredictable sources gathered by the operating system. This is the kind used for passwords, encryption keys and security tokens.

Math.random vs crypto.getRandomValues

In a web browser, Math.random returns a decimal between 0 and 1 from a fast PRNG. It is fine for animations and casual games, but the standard does not require it to be cryptographically secure, and it should not be used where unpredictability matters.

crypto.getRandomValues fills a buffer with values from the browser's CSPRNG. Our generator uses it for every quick pick, lottery line and custom draw, requesting 32-bit values. The only exception is the daily lucky numbers, which deliberately use a small seeded generator so that everyone with the same input sees the same set on the same day; those are labelled as a game, not a random draw.

Modulo bias and rejection sampling

Even with a perfect source, turning raw random values into a range can add bias. The usual shortcut is the remainder, or modulo. Imagine a random byte from 0 to 255 and you want a die roll from 0 to 5. 256 values do not divide evenly by 6: 256 = 6 x 42 + 4. Using byte mod 6, the results 0, 1, 2 and 3 each come from 43 byte values, but 4 and 5 come from only 42. Those faces would turn up slightly more often.

Rejection sampling fixes this. You find the largest multiple of 6 that fits, which is 252, and throw away any byte from 252 to 255, drawing again. Every remaining byte maps to a face exactly 42 times, so each face is equally likely. Our generator does the same with 32-bit values: it rejects anything at or above the largest multiple of the range size, then takes the remainder. For small ranges a redraw is very rare.

Fisher-Yates for draws without repeats

Lottery lines need several different numbers. A careless approach, such as picking until there are no duplicates and then nudging values, can favour some numbers. The Fisher-Yates shuffle avoids this: put every allowed number in a list, then for each position swap in a uniformly chosen item from the part of the list not yet used.

Our generator runs a partial Fisher-Yates shuffle for small or dense pools, stopping once it has enough numbers, and uses the unbiased random index described above for each swap. For a handful of numbers from a very large range it instead redraws any duplicate, which is also unbiased. Numbers you choose to always include or never include are set aside first, and the rest are drawn fairly from what remains.

How to test fairness, and what fair cannot mean

The tool includes a fairness test that draws 10,000 numbers from 1 to 10 and counts each result. A fair generator should give about 1,000 of each, but not exactly 1,000: random variation means typical counts land within a few dozen either side, and the tool reports the largest difference from 1,000 as a percentage. Run it several times and the numbers that come out ahead should change each time.

Statisticians formalise this with a chi-square test, which adds up how far each count is from what was expected, scaled by the expected count, and asks whether that total is larger than chance alone would usually produce. A fair generator passes most of the time; a biased one fails consistently as the sample grows.

Fair does not mean predictive. A fair generator cannot tell you which numbers an official lottery will draw, because those draws use their own certified machines or audited random number systems. Every line has the same odds, nothing improves them, and you should play only where legal and within a budget.

Frequently asked questions

Is this random number generator truly random?

It uses crypto.getRandomValues, the browser's cryptographically secure generator, which is designed to be unpredictable. It then uses rejection sampling so every number in your range is equally likely, without modulo bias.

What is modulo bias?

It is a small unfairness caused by using the remainder to fit random values into a range that does not divide evenly. For example, a byte from 0 to 255 mod 6 makes 0 to 3 slightly more likely than 4 and 5. Rejection sampling removes it.

Is Math.random good enough?

For games and visual effects, usually yes. It is not required to be cryptographically secure, so for anything where unpredictability matters, such as passwords, use crypto.getRandomValues instead.

How can I check that the generator is fair?

Use the fairness test in the tool. It draws 10,000 numbers from 1 to 10. Each should appear roughly 1,000 times, with small random differences that change from run to run.

Why do I sometimes get the same number twice in a row?

If repeats are allowed, that is expected. In a range of 1 to 10, any number follows itself one time in ten. Streaks are a normal part of true randomness, and people often underestimate how common they are.

Can a random generator predict lottery numbers?

No. Official draws use their own certified machines or random number systems, and every combination has the same chance. A generator can give you a fair line quickly, but nothing improves the odds. Play only where legal and within a budget.

For entertainment and education. Random numbers cannot predict or improve the result of a draw, and numerology and astrology are traditions, not science. If you play a lottery, play only where it is legal for your age and location, and set a budget you can afford to lose. Free, confidential help: BeGambleAware (UK), 1-800-GAMBLER (US).