Home › Guides › Random Numbers
How Random Number Generators Work
Last updated: September 2026 · Independently QA-tested formulas
Give me a number between 1 and 10, right now. Whatever you said, you didn't pick randomly — humans avoid round numbers, favor 7, and lean on recent memories. Computers are different: they produce sequences that pass statistical tests for randomness, which is exactly what a random number generator does for picks, draws, dice and raffles.
What is a random number generator?
An RNG is a procedure that outputs values with no usable pattern. Two families exist:
- True random (TRNG): measures physical noise — atmospheric static, thermal jitter, photon arrival times. Unpredictable even in principle, but slower and hardware-dependent.
- Pseudo-random (PRNG): a deterministic algorithm that, given a starting seed, produces a long sequence that looks statistically random. Every online calculator uses this.
For picking a raffle winner or rolling a d20, a PRNG is exactly as fair as a physical die — arguably fairer, since a worn die is biased.
How a range pick works: the formula
Where rand() returns a uniform decimal in [0, 1). Multiplying stretches it across your range, flooring snaps it to whole numbers. Three properties matter:
- Uniformity: each of the (max − min + 1) values gets an equal share.
- Independence: one result never influences the next.
- Inclusive bounds: good implementations map [0,1) so both min and max are reachable.
Worked example: rand() returns 0.2719, range 1–100 → 1 + floor(0.2719 × 100) = 28.
What is a seed?
The seed is the PRNG's starting state. Same seed in, same sequence out — that's how scientists re-run identical simulations. Everyday tools seed from the system clock or OS entropy, so you never see repeats of the same sequence. If a tool lets you set a seed, use it only when you want reproducibility.
Can numbers repeat?
Yes — and they should. Independent draws mean yesterday's result has zero effect on today's. In a 1–10 range, a repeat appears within about 7 picks on average. That feels "unrandom" to humans (the gambler's fallacy) but is mathematically correct. Tools labeled "unique picks" or "no repeats" instead sample without replacement, like dealing cards.
Common uses and how to set them up
| Use case | Setup |
|---|---|
| Raffle / giveaway winner | Number each entrant, generate one value from 1 to N |
| Dice replacement | Min 1, max = sides; one draw per die |
| Lottery-style pick | Use no-repeat mode with your game's range |
| Prize draw with 3 winners | Generate 3 unique values from 1 to N (or re-roll duplicates) |
| Sampling for a survey | Number the population, draw k unique values |
Uniform vs weighted: when equal odds are the wrong answer
Every tool on this page is a uniform generator: each number in the range has exactly the same chance. That is what raffles and dice need — but not everything. Some real picks are weighted:
- Raffle with unequal entries: if A bought 3 tickets and B bought 1, don't generate 1–2 and pick a person. Number every ticket 1–4 and draw once — A's tickets occupy 3 of the 4 numbers, matching the real odds.
- Group assignments that feel random but must be balanced: pure randomness can deal 5 strong players to one team. First shuffle (random), then deal round-robin (structured) — the team randomizer does exactly this.
- Sampling: to survey 50 of 800 students, number the population and draw 50 unique values — unique mode matters here, duplicates would undercount.
Randomness myths that cost people money
- The gambler's fallacy. "Red has come up 5 times, black is due." No — independent draws have no memory. Believing otherwise is how roulette systems and lottery 'streak strategies' lose money.
- The hot-hand flip side. Picking last week's winning numbers because they're 'lucky' is the same error in reverse. Every combination had the same odds last week and this week.
- Confusing rare with impossible — and common with guaranteed. A 1-in-13,983,816 lottery ticket still wins sometimes; a 99% safe bet still loses 1 time in 100. Odds describe long-run frequency, not this week.
A security boundary you should know
PRNGs like Math.random() are ideal for dice, raffles and games — unpredictable enough that nobody can guess your next roll in practice. They are not designed to resist a determined attacker choosing passwords. Password generation needs a cryptographically secure source (CSPRNG), which is why our password generator exists separately from this one. The password entropy guide explains the math of why a 16-character passphrase beats an 8-character string of symbols.
The 2d6 curve: why some dice totals are rarer than others
One honest limitation of "pick a number from 1 to 36" for dice replacement: it gives a flat distribution, while real two-dice throws are peaked. Every one of the 36 (die, die) combinations is equally likely, but a total of 7 has six of them (1+6, 2+5, 3+4, 4+3, 5+2, 6+1) while 2 or 12 have one each:
| Total | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Ways out of 36 | 1 | 2 | 3 | 4 | 5 | 6 | 5 | 4 | 3 | 2 | 1 |
So 7 comes up about 16.7% of the time — six times as often as snake eyes. Board games that "feel wrong" are usually just revealing this curve. For a dice game where the shape of the distribution matters, roll two dice separately (the dice roller does independent draws) rather than one uniform pick from the summed range.
Unique picks: how the odds actually change
Drawing with replacement keeps every draw at the same odds; drawing without replacement shifts them as the pool shrinks. A 6/49 lottery is the classic case: the first ball is a 1-in-49 shot, but the jackpot needs all six — 49 × 48 × 47 × 46 × 45 × 44 ÷ 720 orders = 1 in 13,983,816. That's C(49,6) — combinations, not permutations, because draw order doesn't matter.
The same combinatorics runs a raffle fairly: 150 unique picks from 200 entrants leaves the last entrant facing odds that rose from 1/200 toward 1/51 as others were drawn. Not unfair — just not the constant 1/200 your intuition keeps quoting. When fairness must be visible, publish the method: numbered entrants, unique-mode draw, order ignored.
Worked example: Coin Flip Simulator at its default inputs
This is the answer Coin Flip Simulator gives before you touch anything — the defaults as shipped, computed live rather than copied from a sample.
| Input | Default |
|---|---|
| Number of Flips | 100 |
Result: Heads: 48 | Tails: 52
The steps behind that answer
- Each flip is an independent 50/50 trial
- With 100 flips expect ~50 heads
- Results vary — that is randomness
Number of Flips — three values, three answers
The table below varies number of flips alone — half, the default, and half again.
| Number of Flips | Result |
|---|---|
| 50 | Heads: 20 | Tails: 30 |
| 100 | Heads: 56 | Tails: 44 |
| 150 | Heads: 81 | Tails: 69 |
Read the three rows as a range: the spread between them is how much the answer depends on number of flips alone, with everything else held still.
Related guides
Not every random number is safe to use
A general-purpose generator such as Math.random is fine for a raffle or a dice roll and unsuitable for passwords, tokens or anything an attacker can profit from guessing. Cryptographic generators are slower precisely because they resist prediction.
The distinction is predictability, not appearance. A sequence can look random to a human and be fully determined by a seed an attacker can recover.
Watch the range mapping
Taking a raw random integer modulo a range introduces bias whenever the range does not divide the generator space evenly — the low values come up slightly more often. Rejection sampling avoids it.
The bias is tiny for a game and meaningful for a lottery-sized draw. If the fairness of the draw matters, use a generator that handles the mapping for you.
Seeds, reproducibility and streaks
A seeded generator replays the same sequence every time, which is what makes simulations testable. An unseeded one gives a different run each time, which is what makes shuffles fair.
Long streaks are not evidence of a broken generator. In a thousand coin flips, runs of six or seven in a row are ordinary — the intuition that they should not happen is the thing that is wrong.
Frequently Asked Questions
Is a 50/50 coin flip really 50/50?
A simulated coin flip is — each draw is uniform. Physical flips are slightly biased toward the side that starts facing up, research suggests around 50.8% for a standard flip.
Can I predict the next number?
Not without knowing the internal seed and state. For our tools' purposes (picks, dice, draws), the sequence is unpredictable.
Why do my dice rolls never total the average?
Average results are typical, not guaranteed. Three d6s average 10.5, but any total from 3–18 is possible; extremes are simply rarer. Try the dice roller and watch the spread over many rolls.
Is randomness fair for giveaways?
Yes, provided every entrant maps to exactly one number and the range covers all of them — the team randomizer handles the grouping for you.
Try the calculators
← All guides · Glossary · Methodology
Last updated