Algorithms · LESSON 2
Picking a winner with a random number
Weighted interval drawMass-entrant drawA random number alone can pick a winner. The remainder of a big random number divided by the entrant count is the winning number.
Concept
Why use the "remainder"?
Problem — a random number comes out long and messy, like 852,345,724. But there are only 5 entrants. You cannot use such a huge number as a winning number (there is no entrant #852,345,724).
Solution — so we use the remainder. Any big number divided by 5 leaves a remainder of 0, 1, 2, 3, or 4. That fits the entrant number range exactly.
See examples — whether a short random number or one like 800 million, just take the remainder the same way.
| Random | ÷ entrant count | Quotient (laps) | Remainder | → winning number |
|---|---|---|---|---|
| 14 | 5 | 2 | 4 | No. 5 |
| 853,271,946 | 5 | 170,654,389 | 1 | No. 2 |
| 8 | 3 | 2 | 2 | No. 3 |
| 1,200,000,007 | 7 people | 171,428,572 | 3 | No. 4 |
| 700,000,000 | 8 people | 87,500,000 | 0 | No. 1 |
Even if the random number is 800 million and spins hundreds of millions of laps, where it stops (the remainder) is always smaller than the entrant count. Add 1 to that remainder to get the winning number (remainders start at 0 but numbers start at 1, so we add 1 to line them up — remainder 0 → No. 1, 1 → No. 2 …). But numbers that do not divide evenly — like 17 among 5 — give Nos. 1–3 a slight edge, so those unfair numbers are thrown out and drawn again (rejecting unfair numbers).
Experiment
Draw a random number to pick a winner
Draw a random number among 8 entrants to pick a winner. Draw many times and watch whether everyone is picked evenly.
Entrant info
Press the Draw button.
Cumulative result
Only fair-range numbers are turned into a remainder to set winning numbers 1–8 (unfair ones are dropped). The more you draw, the more evenly everyone is picked — that is what makes it fair.
