My Tool Studio
Generators·4 min read

Random Number Generators: How Fair Draws Work

Picking a number between 1 and 100 sounds too simple to get wrong, yet plenty of generators quietly favour some numbers over others. For a board game that hardly matters. For a raffle with real prizes, a classroom pick or a sample of records to audit, it does. This guide explains where random numbers come from in a browser, the bias hiding in the easy method, when secure randomness is worth insisting on, and the settings that cover the most common draws.

Random Numb…{"id": 14"ok": true}

When a random pick has to be fair

Not every draw is a game.

People reach for a random number generator to settle something they cannot settle by choice: who wins the giveaway, which invoice gets audited, which student answers first, which lottery numbers to play. In each case the value of the draw is that nobody could steer it. A generator that leans toward certain results, or that someone could predict, removes the whole point.

That makes two properties matter. Every number in the range must be equally likely, and the next result must be impossible to guess from earlier ones.

Where browser random numbers come from

Browsers offer two sources. Math.random() is fast and fine for animations and games, but it comes from a small internal state that can be reconstructed from a few outputs, after which every following value is known. crypto.getRandomValues() draws from the operating system's secure source, the same one that seeds encryption keys, and cannot be predicted that way.

The Random Number Generator uses only crypto.getRandomValues(). For ranges wider than about 4.29 billion it joins two 32 bit values into one 53 bit value, so even huge ranges stay smooth. Decimals are made the same way, as a value between 0 and 1 stretched across your range and rounded to the places you ask for.

Modulo bias, the flaw in the easy method

The easy way to turn a random 32 bit value into a number from 1 to 6 is to take the remainder after dividing by 6 and add 1. The catch is that 4,294,967,296 possible values do not split evenly into 6 groups. Four of the six results get one extra chance each. With a die the effect is tiny; with a range like 1 to 3 billion it becomes a real tilt toward the lower numbers.

The fix is rejection sampling. The tool works out the largest multiple of your range size that fits in the raw values, throws away any raw value above it, and draws again. Every remaining value maps onto exactly the same number of results, so every outcome is equally likely. The discarded draws are rare, so there is no visible delay.

Random enough: pseudo-random and true random

Every browser generator, including this one, is technically pseudo-random: a deterministic process seeded with unpredictable input. What separates a good one from a weak one is the seed and the state. The operating system mixes timing noise from hardware and other events into the secure source, and the internal state is too large to guess, so the output is unpredictable for any practical purpose.

Services that sample atmospheric noise or radioactive decay offer true randomness, which matters for some research and regulated gambling. For raffles, classroom picks, audits, games and test data, a secure pseudo-random source with no bias is the right tool and has the advantage of running offline, with no one else seeing the draw.

Settings for common draws

Most real uses fit a handful of patterns, and the presets set several of them in one tap:

  • Giveaway winner: number your entries, set 1 to the last entry, draw 1, or several with No repeats.
  • Dice: Roll a die gives 1 to 6, Two dice gives two separate rolls with repeats allowed, as real dice work.
  • Lottery: Lottery 6 of 49 draws six different numbers and sorts them smallest first. Change the range and count for other games.
  • Random order: 1 to 30 with How many 30 and No repeats shuffles a class list or a presentation order.
  • Samples and test data: up to 10,000 values, whole or decimal, then Download CSV.
  • Excluding values: type numbers to skip, such as already-drawn tickets, in Never pick.

Random number mistakes worth avoiding

A fair generator can still produce an unfair draw if the setup is sloppy:

  • Forgetting No repeats in a raffle, so the same ticket can win twice.
  • Numbering entries with gaps, which gives some people no chance and makes others harder to trace.
  • Redrawing until the result looks right. Decide the rules first and accept the first draw.
  • Drawing in private. Share your screen or keep a screenshot; the Earlier draws list gives a simple record.
  • Using a random number for security codes and then writing it on a sticky note. The draw was safe; the storage was not.

Random Number Generator with the other random tools

Numbers are one kind of randomness. The Password Generator uses the same secure source to build passwords, passphrases and PINs, the UUID Generator makes unique identifiers for records, and the Random Name Generator produces people-shaped test data. Pick the number tool whenever the answer is a quantity, a position or a winner.

Try it now

Open Random Number Generator

The tool is one click away. No sign up, no upload, no payment.

Open Random Number Generator