How random is a browser random number?
Math.random is not built for raffles, modulo bias skews dice, and sampling without replacement changes the odds. What browsers really do.
2026-12-04
Two functions, two very different jobs
Math.random returns a number between 0 and 1, and the specification makes no promise about cryptographic quality. Engines start with a state seeded from system entropy, then keep computing with a classic PRNG. In some implementations, watching enough outputs is enough to reconstruct that internal state. It is fine for particle positions, game feel or shuffling a shopping list; it is wrong for prizes, money or access codes.
crypto.getRandomValues fills a typed array from the operating system's CSPRNG. It cannot be seeded to replay a sequence, and its output does not reveal the internal state. That is the source behind Random Number Generator. The shuffle in Text Line Tools, by contrast, runs on Math.random: adequate for reordering lines, unsuitable for picking a winner.
The modulo bias that fits in one line
2^32 is 4,294,967,296. Divided by 6 it gives 715,827,882 with a remainder of 4, so four values receive one extra chance per full cycle while the last two do not. The gap is tiny, roughly one extra hit per 716 million draws for each affected value, but it is real, and the same pattern appears for 7, 9 or 10 faces whenever the range does not divide 2^32.
Rejection sampling fixes it: compute the largest multiple of the range below 2^32, keep drawing until the value falls under that limit, then take the remainder. For a d6 only 4 values out of 4.29 billion are discarded, so a second attempt is effectively never needed. It costs a few lines of code, and it is the only honest way to claim an unbiased result.
Without replacement, the denominator moves
Drawing 3 names from 10 means the first has a 1 in 10 chance, the second 1 in 9 among those left, the third 1 in 8. The pool has to shrink. If you instead run the same 1-of-10 draw three times independently, one person can come up twice or three times. Award first, second and third prize in three separate clicks and you get duplicate winners, then a redraw, and every redraw rule changes the odds again.
The list mode in Random Number Generator removes each pick with splice, so the denominator falls automatically; duplicate lines are merged first, and the cap is 200 names. Text Line Tools reaches the same result by shuffling the list and taking the first three. That is fine for forming groups, but not for a prize draw you may have to defend.
Why 3 out of 10 is not automatically 30%
On the numbers 1 to 10, a single draw gives a specific person 10%. Three draws without replacement give 30%, and here even the naive 10 + 10 + 10 is correct, but only because the three slots are mutually exclusive: nobody can be first and second at once. The complement agrees: 1 − (9/10 × 8/9 × 7/8) = 1 − 7/10 = 3/10.
With replacement the picture changes. The same person can be drawn more than once, so adding 10% three times double-counts those overlaps; the correct figure is 1 − 0.9^3 = 27.1%. The 2.9-point gap looks small, yet across 100 raffles it amounts to about three extra winning chances. If the rule says one win per person, quote 30%; if repeat wins are allowed, quote 27.1%. The rule picks the model, not the arithmetic. Percentage Calculator helps express it, but it cannot choose the assumption for you.
Reproducible is not the same as auditable
crypto.getRandomValues has no seed, so the exact sequence cannot be replayed. That protects the draw from prediction, but it also makes a dispute hard to settle. A screenshot can be edited in seconds. A screen recording with a visible clock, the participant list and an uninterrupted run is stronger evidence; a public draw also needs a third-party witness, a sealed list and publication of both entrants and results.
Before the draw you can publish a SHA-256 hash of the participant list, computed with Hash Generator, and afterwards publish the list and the result. Anyone can recompute the digest and confirm the list was not swapped. That proves list integrity, not fairness. This tool is not a certified lottery system, keeps no audit trail and issues no seed commitment. Regulated draws or draws with meaningful prizes need a certified randomness service and legal review.
Dice sums and the jobs this tool should refuse
A fair d6 shows each face with probability 1/6 ≈ 16.67%. Two dice have 36 equally likely combinations; a sum of 7 occurs in 6 of them, so 6/36 ≈ 16.67%, the same number as a single face but for a different reason. The sums 2 and 12 have exactly one way each: 1/36 ≈ 2.78%. The distribution is triangular, not flat. Treating 2d6 as a uniform number from 2 to 12 turns a rare roll into a common one.
Do not use this tool for passwords, API keys or recovery codes. Even with crypto.getRandomValues, you would need an unbiased mapping onto a character set and enough length; this page returns numbers and manages no secrets. Hash Generator is a verification tool for checksums and integrity, not a password hasher — passwords belong in a real auth system with scrypt or Argon2. Randomness is infrastructure: the code path matters more than the label on the button.