hasibai

Math

Random number generator

Draws from the browser’s cryptographic generator rather than Math.random, and without the modulo bias that skews naive implementations.

Draw
Enter your figures to see the breakdown.

Why not just use Math.random?

JavaScript's Math.random() is a pseudorandom generator seeded by the browser and optimised for speed. It is fine for animations and shuffling a playlist, but its output is not required to be unpredictable and implementations have varied in quality.

This generator uses crypto.getRandomValues, which draws from the operating system's cryptographically secure entropy pool — the same source used for encryption keys. For anything where fairness matters, such as a prize draw, that distinction is worth having.

Modulo bias, and how it is avoided

The obvious way to map a random 32-bit integer into a range is to take the remainder after division. It is also subtly wrong. If the range does not divide evenly into 232, the lowest values in the range come up slightly more often, because they are reachable from one extra starting value.

The bias is tiny for small ranges but real, and it grows as the range approaches the size of the source. The fix, used here, is rejection sampling: discard any draw that falls in the uneven remainder at the top and try again. The result is exactly uniform, at the cost of an occasional extra draw.

Drawing without repeats

Selecting six different numbers from 1 to 49 is sampling without replacement. The naive approach — draw, check for duplicates, redraw if found — degrades badly when the count approaches the range size.

This calculator uses a partial Fisher-Yates shuffle instead, which picks each successive value from the remaining pool in constant time per draw. It gives every possible combination an equal chance regardless of how much of the range you are drawing.

Randomness is streakier than people expect

Genuinely random sequences contain runs and clusters that look suspicious. In 100 coin flips, a run of six or more of the same result is more likely than not. In a lottery draw, consecutive numbers appear far more often than intuition suggests.

People asked to write down a "random" sequence produce something far too evenly spread — alternating too often and avoiding repeats. This is why a result that looks patterned is not evidence of a broken generator, and why manually invented numbers are a poor substitute for a real draw.

Common questions

Can I use this for a prize draw?

The generator is unbiased and cryptographically seeded, which is technically sound. For draws with legal or commercial consequences, check the rules that apply to you — some jurisdictions require documented, auditable procedures regardless of the quality of the underlying randomness.

Is the result different every time?

Yes. There is no seed you can set, so the same inputs produce a fresh draw on every press. This makes results non-reproducible by design, which is what you want for a draw and unhelpful if you need repeatable test data.

How do I simulate dice?

Set the range from 1 to 6, choose how many dice, and allow repeats — real dice are independent, so repeats must be possible. For two six-sided dice, draw two numbers and add them; do not draw once from 2 to 12, which would make every total equally likely and misrepresent the distribution.

Why does my draw contain consecutive numbers?

Because that is normal. In a six-from-49 draw, roughly half of all possible combinations contain at least one consecutive pair. Their absence would be more surprising than their presence.