Unipicker draw logic
See Unipicker's main draw logic.
Unipicker selects winners with the logic below.
- Obtain a "seed" from the "seed issuance server."Pass the "seed" as the input to the "random number generation algorithm."
- Assign a random number to each entrant.
- Sort entrants by their random number.
- For group draws, a random number is also assigned to the draw settings.A group draw means picking winners group by group. This type of draw requires draw-settings input that sets the number of winners per group info (rank or prize name, or apartment building/unit — anything that distinguishes winners). Unipicker assigns a random number not just to entrants but to the draw settings too.
- Sort the draw settings by their random number.
- Take the sorted entrants in order and assign (declare winners) them to the sorted draw settings.
| Entrant | Random |
|---|---|
| James | 0.2498216440435499 |
| Michael | 0.5390021712519228 |
| David | 0.4989048286806792 |
| Chris | 0.881228075362742 |
| Brian | 0.2693764951545745 |
| Kevin | 0.3479937631636858 |
| Steve | 0.7156692454591393 |
| Draw settings | Random |
|---|---|
| 101-101 | 0.05107798264361918 |
| 101-504 | 0.5512312969658524 |
| 103-502 | 0.3550391604658216 |
| 105-701 | 0.26768961385823786 |
| 105-903 | 0.36229446344077587 |
| Entrant | Random |
|---|---|
| Chris | 0.881228075362742 |
| Steve | 0.7156692454591393 |
| Michael | 0.5390021712519228 |
| David | 0.4989048286806792 |
| Kevin | 0.3479937631636858 |
| Brian | 0.2693764951545745 |
| James | 0.2498216440435499 |
| Draw settings | Random |
|---|---|
| 101-504 | 0.5512312969658524 |
| 105-903 | 0.36229446344077587 |
| 103-502 | 0.3550391604658216 |
| 105-701 | 0.26768961385823786 |
| 101-101 | 0.05107798264361918 |
| — | — |
| — | — |
Unipicker's weighted draw has 2 methods: the weighted interval draw method and the weighted key draw method.
Apart from seed generation, the random numbers used in the weighted draw logic can be made using either the SHA-256(seed|N) method¹ or the xoshiro(seed) method².
Unipicker applies the weighted interval draw, one of its weighted draw methods, as follows.
- Shuffle the entrant list at random.Shuffle the entrant list at random using the Fisher-Yates shuffle algorithm³. Entrants are placed according to the shuffled order, and each entrant gets a winning interval sized in proportion to their weight.
- Shuffle the draw settings at random.Shuffle the draw settings at random using the Fisher-Yates shuffle algorithm³.
- Generate the "target value."(1) The "target value" ranges from 1 to the "total entrant weight." (2) Generate a random number within that range and use it as the "target value." e.g., if the "total entrant weight" is 600, the random-generation range is 1 to 600.
- Select the winner.Walk through the entrant list in order, and if the "target value" falls within a particular entrant's "winning interval," select that entrant as the winner.
- Assign the winner to the draw settings.Assign the selected winner, in order, to the shuffled draw settings. Repeat steps 3–6 until every draw-setting item has a winner assigned.
- Remove an entrant selected as a winner from the pool for subsequent rounds.Reset the winning intervals based on the remaining entrants, and recompute the total entrant weight. e.g., if the weight total was 600 and the winner's weight was 160, the next range is 1 to 440.
| Entrant | Weight (W) |
|---|---|
| Charlie | 150 |
| Naomi | 50 |
| Kevin | 10 |
| Olivia | 200 |
| Steve | 160 |
| Andrew | 100 |
| Brian | 30 |
shuffle
| Entrant | Weight (W) |
|---|---|
| Andrew | 100 |
| Olivia | 200 |
| Charlie | 150 |
| Naomi | 50 |
| Brian | 30 |
| Kevin | 10 |
| Steve | 160 |
Swap the last (7th) seat's entrant with the entrant in a seat randomly drawn from 1–7 — here, the 5th seat (Brian ↔ Steve)
Swap the seat before that (6th) with a seat randomly drawn from 1–6 — here, the 3rd seat (Andrew ↔ Kevin)
…
| Draw settings |
|---|
| Rank 1 |
| Rank 2 |
| Rank 3 |
shuffle
| Draw settings |
|---|
| Rank 2 |
| Rank 1 |
| Rank 3 |
Swap the last (3rd) setting with the setting in a seat randomly drawn from 1–3 — here, the 3rd seat (same seat, so no swap)
Swap the one before that (2nd) with a seat randomly drawn from 1–2 — here, the 1st seat
random number
| Entrant | Weight | Winning interval | |
|---|---|---|---|
| Andrew | 100 | 1 ~ 100 | |
| Olivia | 200 | 101 ~ 300 | |
| Winner selected | Charlie | 150 | 301 ~ 450 ← 412 target value |
| Naomi | 50 | 451 ~ 500 | |
| ⋮ | ⋮ | ⋮ | |
| Steve | 160 | 541 ~ 700 |
After removing Charlie, the weight total changes 700 → 550, and the remaining entrants' winning intervals are recomputed.
- [1] Durstenfeld, R. (1964). Algorithm 235: Random Permutation. Communications of the ACM, 7(7), 420.
- [2] Fisher–Yates Shuffle. Wikipedia. en.wikipedia.org/wiki/Fisher-Yates_shuffle
Unipicker applies the weighted key draw, one of its weighted draw methods, as follows.
- Assign a random number to each entrant.Issue every entrant one random number (u) between 0 and 1.
- Generate a Key value that reflects each entrant's weight.Compute each entrant's Key value from the issued random number (u) and their weight (w). A bigger weight makes a smaller Key more likely, and win priority is set in ascending order of Key value.
- Sort the entrant list ascending by the computed Key value.
- Shuffle the draw settings at random.Shuffle the draw settings at random using the Fisher-Yates shuffle algorithm¹.
- Assign the entrants, sorted by Key value, in order to the shuffled draw settings (winners).
※ Based on the weighted sampling algorithm proposed by Efraimidis–Spirakis (2006).
| Entrant | Weight (W) | Random (U) | −ln(u) | key=−ln(u)/w |
|---|---|---|---|---|
| Charlie | 150 | 0.73 | 0.3147 | 0.002098 |
| Naomi | 50 | 0.41 | 0.8916 | 0.017832 |
| Kevin | 10 | 0.95 | 0.0513 | 0.005129 |
| Olivia | 200 | 0.12 | 2.1203 | 0.010601 |
| Steve | 160 | 0.53 | 0.6349 | 0.003968 |
| Andrew | 100 | 0.75 | 0.2877 | 0.002877 |
| Brian | 30 | 0.44 | 0.8210 | 0.027366 |
| Order | Entrant | Weight (W) | Random (U) | −ln(u) | key=−ln(u)/w |
|---|---|---|---|---|---|
| 1 | Charlie | 150 | 0.73 | 0.3147 | 0.002098 |
| 2 | Andrew | 100 | 0.75 | 0.2877 | 0.002877 |
| 3 | Steve | 160 | 0.53 | 0.6349 | 0.003968 |
| 4 | Kevin | 10 | 0.95 | 0.0513 | 0.005129 |
| 5 | Olivia | 200 | 0.12 | 2.1203 | 0.010601 |
| 6 | Naomi | 50 | 0.41 | 0.8916 | 0.017832 |
| 7 | Brian | 30 | 0.44 | 0.8210 | 0.027366 |
| Draw settings |
|---|
| Rank 1 |
| Rank 2 |
| Rank 3 |
shuffle
| Draw settings |
|---|
| Rank 2 |
| Rank 1 |
| Rank 3 |
Swap the last (3rd) setting with the setting in a seat randomly drawn from 1–3 — here, the 3rd seat (same seat, so no swap)
Swap the one before that (2nd) with a seat randomly drawn from 1–2 — here, the 1st seat
| Order | Entrant | Weight (W) | key | Draw settings (after shuffle) | Result |
|---|---|---|---|---|---|
| 1 | Charlie | 150 | 0.002098 | Rank 2 | Winner |
| 2 | Andrew | 100 | 0.002877 | Rank 1 | Winner |
| 3 | Steve | 160 | 0.003968 | Rank 3 | Winner |
| 4 | Kevin | 10 | 0.005129 | — | Lost |
| 5 | Olivia | 200 | 0.010601 | — | Lost |
| 6 | Naomi | 50 | 0.017832 | — | Lost |
| 7 | Brian | 30 | 0.027366 | — | Lost |
- Efraimidis, P. S., & Spirakis, P. G. (2006). Weighted Random Sampling with a Reservoir. Information Processing Letters, 97(5), 181–185.
This draw determines the draw random number from the Unipicker random seed and a ball number drawn on-site.
A draw participant or organizer can join the draw in person for even greater fairness.
Fairness can only be guaranteed, however, when the whole process is disclosed live in real time.
Entrant's draw random number = 39540329
Unipicker applies the ball-number public draw logic below.
- Assign each entrant a random number generated by Unipicker.After stripping the generated random number down to its decimal digits, assign its first 10 digits (the Unipicker random number).
- Multiply the entrant's Unipicker random number by the ball number.Use the ball number drawn publicly on-site.
- Sort entrants by the last 8 digits of the product.
- Process the sorted entrants as winners in order.
Unipicker's basic draw logic assigns a random number to each entrant to pick winners. But PC CPU and memory limits make it unsuited to mass draws.
A mass draw assigns each entrant an entry number in order and uses a computer random number to draw winning numbers.
To draw fair random numbers it applies "1. the unfair-number rejection policy," and to efficiently check for duplicate winning numbers it uses "2. Floyd's Sampling Without Replacement."
| Entry number | Entrant |
|---|---|
| No. 1 | James |
| No. 2 | Daniel |
| No. 3 | Ryan |
| No. 4 | Tom |
| No. 5 | Mark |
In practice, Unipicker can generate random numbers up to 9,007,199,254,740,992 (2⁵³).
Using <Figure 4>'s assumptions to draw a computer random number and decide 1 winner, the winning numbers can generally be laid out by computer random number as below.
| Fair random-number range (only multiples of the entrant count are used) | Unfair rejected | |||||||||||
| Random No. | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| Winning no. (winner) | No. 1 James | No. 2 Daniel | No. 3 Ryan | No. 4 Tom | No. 5 Mark | No. 1 James | No. 2 Daniel | No. 3 Ryan | No. 4 Tom | No. 5 Mark | No. 1 James | No. 2 Daniel |
e.g., if the generated random number is 4, No. 4 Tom is selected; if 8, No. 3 Ryan is selected as the winner.
As above, if the computer's generated random-number range (1–12) is used as is, a random number of 11 or 12 gives James and Daniel a higher win probability than everyone else.
| Entry number | Entrant | Win chances |
|---|---|---|
| No. 1 | James | 3× (1, 6, 11) |
| No. 2 | Daniel | 3× (2, 7, 12) |
| No. 3 | Ryan | 2× (3, 8) |
| No. 4 | Tom | 2× (4, 9) |
| No. 5 | Mark | 2× (5, 10) |
rejected
| Entry number | Entrant | Final chances |
|---|---|---|
| No. 1 | James | 2× (1, 6, |
| No. 2 | Daniel | 2× (2, 7, |
| No. 3 | Ryan | 2× (3, 8) |
| No. 4 | Tom | 2× (4, 9) |
| No. 5 | Mark | 2× (5, 10) |
If the computer random number generated for a fair probability comes up 11 or 12, it is discarded and a new computer random number is generated instead.
In other words, a valid computer random number only uses the range that is a multiple of the entrant count; anything beyond that is rejected.
This is called the "unfair-number rejection policy."
To keep winning numbers from repeating, every draw must be checked against existing winning numbers for duplicates. If the number of winners needed is very large or duplicates occur often, this check can repeat excessively — so mass-entrant winner draws apply Floyd's Sampling Without Replacement.
Using <Figure 4>'s assumptions to draw computer random numbers and decide a total of 3 winners, duplicate draws can be prevented as below.
James
Daniel
Ryan
Tom
Mark
| Draw | Entry-number range | Result | Winning-number list |
|---|---|---|---|
| (1) 1st | 1 ~ 3 | Computer random number 11 → No. 2 | No. 2 |
| (2) 2nd (duplicate occurs) | 1 ~ 4 | Computer random number 2 → No. 2 (duplicate) → newly added No. 4 wins | No. 2, No. 4 |
| (3) 3rd | 1 ~ 5 | Computer random number 6 → No. 1 | No. 2, No. 4, No. 1 |
1st draw range = total entrants − total winners + 1 (=3); the range grows by 1 with each subsequent draw.
This logic is efficient because it never needs to regenerate a computer random number even when a duplicate comes up.
Entrants No. 1–3 get 3 draw chances, No. 4 gets 2, and No. 5 gets just 1 — which may look unfair. But if a duplicate winner turns up on the 2nd draw, No. 4 is selected as the winning number, and on the 3rd draw the existing numbers are likely to repeat, raising No. 5's chance of winning — so applying this logic effectively and fairly prevents duplicate draws.
- Robert Floyd’s Tiny and Beautiful Algorithm. nowherenearithaca.com
- A Sample of Brilliance. Fermat’s Library. fermatslibrary.com/s/a-sample-of-brilliance
After winners are selected by the mass-entrant winner draw logic, the last winner's computer random number is used as the seed to assign each winner a new random number and set their order in the draw.
Running the order assignment with <Figure 5>'s assumptions gives the following.
Assume the initial "seed" value issued by Unipicker's "seed issuance server" is 161925012407392416.
| Winner info | Random |
|---|---|
| No. 2 Daniel | 0.677889 |
| No. 4 Tom | 0.321264 |
| No. 1 James | 0.473173 |
| Order | Random | Winner info |
|---|---|---|
| 1 | 0.677889 | No. 2 Daniel |
| 2 | 0.473173 | No. 1 James |
| 3 | 0.321264 | No. 4 Tom |
