Three kinds of randomness
- Pseudo-random generators (PRNGs) start from a number called a seed and use a formula to produce a long sequence that looks random. Same seed, same sequence. They're fast and fine for games and simulations. JavaScript's
Math.random()is one. - Cryptographically secure generators (CSPRNGs) are designed so that seeing past outputs doesn't let anyone predict the next one. Operating systems seed them from unpredictable sources such as hardware timing. In a browser,
crypto.getRandomValues()is one, and it's what the random picker uses. - Hardware or "true" random generators measure physical noise directly. Secure generators often mix this in.
The hidden bias in a simple range
Turning raw random bits into a number in your range is where many tools go subtly wrong. Say you have a random byte (0 to 255, 256 values) and want a die roll from 1 to 6 by taking the remainder after dividing by 6. 256 = 42 × 6 + 4, so the remainders 0 to 3 can come up 43 ways and 4 and 5 only 42 ways. Faces 1 to 4 become very slightly more likely than 5 and 6.
The fix is rejection sampling: throw away the top 4 values (252 to 255) and draw again, so every face has exactly 42 ways. The random picker does this with 32-bit numbers, so every value in your range has exactly the same chance.
Fair shuffles
The standard fair shuffle is Fisher-Yates: go from the last item to the first, and swap each one with a randomly chosen item at or before it. Every possible order comes out equally likely. A common shortcut, sorting a list by a random number each time items are compared, is not reliably fair: depending on the sorting method, some orders turn up more often than others.
Splitting into teams fairly is then easy: shuffle, then deal names out one at a time like cards, so team sizes differ by at most one.
The odds behind common draws
- Picking one name from 8: each person has a 1 in 8 chance, 12.5%.
- Choosing 6 numbers from 1 to 49: there are 13,983,816 possible combinations (49 choose 6). A random pick is exactly as likely to win as a "lucky" one.
- Repeats happen more than people expect. Draw 10 numbers from 1 to 100 with repeats allowed and the chance that at least two match is about 37%. Tick "No repeats" if that matters.
- The birthday problem: in a group of 23 people, the chance that two share a birthday is about 50.7% (ignoring leap days and assuming birthdays are evenly spread).
Does random look random?
Real randomness clumps. Streaks such as three heads in a row or the same number twice in a short list are normal, and a sequence that never repeats is actually a sign something isn't random. If a result feels suspicious, check the settings (range, repeats) rather than the generator.
Running a fair draw
- Publish the list of entries and the rules first: how many winners, whether one person can win twice.
- Remove accidental duplicates, unless multiple entries are allowed.
- Do the draw where people can see it, live or recorded.
- Save the result straight away. A tool that stores nothing, like this one, leaves the screen as the only record.
For prize promotions, local laws may set extra rules, so check them for anything beyond a casual giveaway.
Common mistakes
- Using modulo without rejection for ranges that don't divide evenly.
- Re-seeding a PRNG with the time on every call, which can return the same number twice in the same millisecond.
- Sorting by random to shuffle. Use Fisher-Yates.
- Using Math.random() for anything security-related, such as tokens or passwords. Use a cryptographic generator.
- Forgetting the range is inclusive. 1 to 10 includes both 1 and 10, which is 10 values, not 9.
Frequently asked questions
How does a random number generator work?
A pseudo-random generator turns a seed into a long, random-looking sequence with a formula. Secure generators are seeded from unpredictable sources so outputs can't be predicted.
Is Math.random() truly random?
No. It's a fast pseudo-random generator, fine for games but not designed to be unpredictable. Use crypto.getRandomValues() for draws or security.
How do I pick a random number between 1 and 100 fairly?
Use a generator that avoids modulo bias, such as one using rejection sampling. The random picker does this.
What is the fairest way to shuffle a list?
The Fisher-Yates shuffle, which makes every order equally likely.
Why did I get the same number twice?
With repeats allowed, matches are common. 10 draws from 1 to 100 repeat at least once about 37% of the time.
Can a random picker be used for a raffle?
For casual giveaways, yes. Publish the rules and entries first and make the draw visible.