Skip to content

How a fair prize wheel promo works

Odds, stock, daily limits and coupon codes for a spin-the-wheel promo, from the logic behind my Prize Parade demo and the tests that check it.

· Updated · 4 min read

Prize Parade, a gamified bakery promo with a wheel of fortune, a scratch card and an advent calendar

In a fair spin-the-wheel promo the prize is drawn first and the wheel is animated afterwards. The animation only acts out a result that the campaign logic has already decided, which means the odds are in a table you can read and test, not in the physics of a spinning sprite.

I built this for a fictional bakery in a demo called Prize Parade. Everything below is the campaign logic behind it. A real campaign would run it on a server, because code in a browser can be changed by the visitor.

The prize table#

Each prize has a weight, a stock and some fine print. The weights in the demo sum to 1,000, so a weight reads as "per thousand plays": the free croissant has 120, the free flat white 100, the cookie 160, and 10% off 220. A "try again" slot has no coupon.

export type Prize = {
  id: string;
  name: string;
  weight: number; // relative weight in the draw; 0 takes the prize out
  stock: number | null; // null is unlimited
  lose?: boolean; // the "try again" slot: no coupon
  terms: string;
};

The draw#

A weighted draw is a few lines. Prizes that are sold out are left out first, so the remaining weights scale up to fill the gap.

export function draw(prizes, stock, rng, opts = {}) {
  const live = available(prizes, stock, opts);
  const total = live.reduce((t, p) => t + p.weight, 0);
  if (total <= 0) return loseOf(prizes);
  let r = rng() * total;
  for (const p of live) {
    r -= p.weight;
    if (r < 0) return p;
  }
  return live[live.length - 1]!;
}

The consequence of dropping sold-out prizes is that the stated odds change during the campaign. The demo has a "How odds work" dialog that shows the live sheet, which is the honest way to present it.

One call, play(campaign, mechanic, rng), does everything for a play: it checks the daily limit, draws the prize, takes stock and issues the coupon. The client only shows the result.

Prove the odds with a test#

The test I trust most draws a million times and compares every prize with its listed chance:

const n = 1_000_000;
// ...
expect(Math.abs((counts[id] ?? 0) / n - chance)).toBeLessThan(0.002);

Every prize has to land within 0.2 percentage points of its listed chance. A second test runs 20,000 plays and checks that stock never goes below zero.

The random generator is seeded (mulberry32), so a test, a screenshot or a ?seed= link can replay the same campaign exactly. In production you would not seed it from the URL.

Daily limits#

Limits are plain data: three wheel plays and three scratch cards per campaign day, and one advent box.

export const DAILY: Record<Mechanic, number> = { wheel: 3, scratch: 3, advent: 1 };

spendAttempt returns a new state, or null when the day's limit is reached, and it never changes the old state. Attempts read back from storage are cleaned: malformed values are dropped and counts are capped at the daily limit. Anyone can still clear them, so in the demo this only guards the interface, because the state lives in the browser. On a server you would key the limit to an account or a verified contact.

Coupon codes that catch typos#

Codes look like CRUMB-XXXX-XXXX. They use a 32-character alphabet with no 0, O, 1 or I, so a cashier reading one out cannot confuse them. Seven characters are random and the eighth is a check character from the Luhn mod N algorithm.

export function isValidCoupon(code: string): boolean {
  const m = /^CRUMB-([2-9A-HJ-NP-Z]{4})-([2-9A-HJ-NP-Z]{4})$/.exec(code.trim().toUpperCase());
  if (!m) return false;
  const all = m[1]! + m[2]!;
  return checkChar(all.slice(0, 7)) === all[7];
}

A test confirms that every single-character typo is rejected. The check character catches typing mistakes at the till, but it does not make a code unforgeable. A real system also needs to look the code up on a server and mark it used.

The animation comes last#

planSpin takes the drawn prize, works out a rotation that ends inside that prize's segment, and keeps the spin between 3 and 6.5 seconds with at least three turns. The slow-down follows angle = travel × (1 − (1 − t)^2.6), and its starting speed matches the speed of the flick or button press.

In my demo the stop is sometimes placed one peg short of a big prize, a deliberate near-miss. It does not change the odds, because the prize was already drawn, but it is a persuasion pattern. Some promotion and gambling rules touch on how outcomes are displayed, and I have not checked any jurisdiction's, so check with a lawyer before copying this. I am not giving legal advice.

Accessibility#

Under reduced motion the wheel jumps to its result behind a short fade, and a tap lifts the whole scratch foil. A polite live region reads every result out, and the canvas is hidden from screen readers, because the result is also in the HTML.

What this demo leaves out#

This is a demo with made-up prizes, and nothing is sent anywhere. I have not run it against real redemption data or had its rules reviewed legally.