The short version
- The result is decided first. The spin you watch is built afterwards to end on it.
- The randomness comes from
crypto.getRandomValues, the generator your browser provides for security work.Math.randomis not used anywhere in this site's own code. - Every entry gets one ticket unless you give it more. The wheel does not remember earlier spins and has no setting, hidden or otherwise, that favors an entry.
- The pick happens in your browser. No server takes part, so nothing outside your device can influence a result.
How a result is drawn
Picking one of 7 entries means choosing a whole number from 0 to 6 with each equally likely. The browser hands out raw random numbers from 0 to 4,294,967,295. That range does not divide evenly by most list sizes, so a shortcut (dividing and keeping the remainder) would make the first few entries very slightly more likely. This code throws away the few raw values that would cause that and draws again. The method is called rejection sampling.
// A whole number from 0 to n - 1, each equally likely.
export function randInt(n) {
if (!Number.isInteger(n) || n < 1 || n > 4294967296) {
throw new RangeError('randInt needs a whole number from 1 to 2^32');
}
// 2^32 raw values rarely divide evenly into n groups. The leftover values
// at the top would make some results slightly more likely, so they are
// thrown away and drawn again (rejection sampling).
const limit = 4294967296 - (4294967296 % n);
let value = raw32();
while (value >= limit) value = raw32();
return value % n;
}
With that in hand, picking an entry is a ticket draw. Each entry holds one ticket, or more if you gave it a weight. One ticket number is drawn and the code walks down the list to find its owner.
// Which entry wins. weights[i] is how many tickets entry i holds (1 unless
// you gave it more with "x3"). One ticket is drawn; its owner wins.
export function pickWeighted(weights) {
let total = 0;
for (let i = 0; i < weights.length; i++) total += weights[i];
let ticket = randInt(total);
for (let i = 0; i < weights.length; i++) {
if (ticket < weights[i]) return i;
ticket -= weights[i];
}
throw new Error('unreachable');
}
That is the whole decision. The code above is copied into this page from the files the site runs each time the site is built, so it cannot drift from what happens when you press Spin.
Shuffles: the list randomizer, the team maker, Shuffle in the editor
Putting a whole list in random order uses the Fisher-Yates shuffle: walk the list from the end, and swap each item with one chosen at random from the items not yet placed, itself included. Each choice is one call to randInt above, which makes every possible order equally likely.
// Fisher-Yates shuffle: every possible order is equally likely.
export function shuffle(list) {
const out = list.slice();
for (let i = out.length - 1; i > 0; i--) {
const j = randInt(i + 1);
const keep = out[i];
out[i] = out[j];
out[j] = keep;
}
return out;
}
The spin is a replay of the decision
When you press Spin, these lines run before the wheel moves:
// 1. Decide the result. Nothing after this line can change it.
const winner = pickWeighted(entries.map((e) => e.weight));
// 2. Work out the angle that puts that slice under the pointer, a few
// turns from now, stopping at a random spot inside the slice.
const dir = o.dir === -1 ? -1 : 1;
const seconds = Math.min(Math.max(Number(o.seconds) || 5, 1), 12);
const from = rot;
const to = endRotation(slices, winner, from, randFraction(), turnsFor(seconds), dir);
// 3. Animate from where the wheel is to that angle.
Step 1 picks the entry. Step 2 works out the angle that puts that entry's slice under the pointer, a few turns ahead, at a random spot inside the slice (so it does not always stop dead center, and never on a line). Step 3 turns the wheel to that angle along one smooth slowdown curve that ends exactly there. There is no nudge at the end, and the result is shown only after the wheel has stopped. If your device asks for reduced motion, the wheel fades to the result instead of turning.
Run 10,000 spins yourself
This calls the same pickWeighted function 10,000 times, with no animation, on whatever list is in the box, and counts how often each entry came up. The red mark is the expected count. With 10,000 spins the bars land close to the marks but not exactly on them; a perfect match every time would be the suspicious result.
times it came up expected
What weights do
Write Pizza x3 and Pizza holds three tickets instead of one, and its slice is drawn three times as wide, so the wheel shows what you set. A wheel with any weight on it says so under the list. A wheel is never weighted unless the list says so in plain text, and a shared link carries the same text, so whoever opens it can read every weight.
What the tests check
The engine has automated tests. One draws 1,000,000 numbers over 7 outcomes and applies a chi-square test to the counts. One draws 400,000 times from a x3, b and checks the 3 to 1 ratio. One simulates 10,000 spins on wheels of 1 to 1,000 entries and checks that the slice under the pointer at the final angle is the entry that was drawn, every time. The number picker, coin, dice and team maker have the same kind of test.
What is stored, and where
- Your entries are not sent to this site and are not sent to analytics. There is no account and no server-side copy of any wheel.
- Saved wheels, the list you were last working on, a draw in progress, and your sound and color choices sit in this browser's own storage. Clearing site data removes them. They do not sync to other devices.
- A shared link carries the list inside the link itself, in the part after the # sign. Browsers do not send that part to any server. When a shared link is opened, the page reads the list and removes it from the address bar before any analytics or advertising code runs, so the list is not in the address those tools see.
- An embedded wheel carries no ads and no analytics tags. It sends one count ("an embed loaded on this site"), without the entries.
- Opening someone's shared link never changes the list this browser keeps for you: the shared wheel is shown with a label, and a reload brings your own list back.
The privacy policy lists the analytics and advertising tools that run on the pages around the wheel.
What this cannot promise
The wheel is as random as your browser's cryptographic generator, which is the same one that protects secure connections. It cannot know whether a name was typed twice (Remove duplicates is in the editor), and it cannot stop someone editing a list before a spin: for a public draw, show the list on screen, then spin. It is not a certified system for regulated drawings such as lotteries or sweepstakes with legal rules.