Dev.to WebDev 🛠 Dev 👁 2 📖 2 min read

Building a fair decision wheel that runs entirely in the browser

Most wheel spinners look simple: draw some slices, rotate, read the result. The part that took the longest on WheelYesNo (https://wheelyesno.com) was not the drawing. It was making the result provably fair while everythi

Most wheel spinners look simple: draw some slices, rotate, read the result. The part that took the longest on WheelYesNo (https://wheelyesno.com) was not the drawing. It was making the result provably fair while everything runs client-side, with no server to trust.

Three decisions shaped the build:

1. Pick the winner before the wheel moves.
A spin animates for about five seconds, and it is tempting to compute the result from where the wheel stops. That couples fairness to animation timing and frame rates. Instead, the winning slice is chosen the moment the spin starts, and the animation is then planned backwards so the wheel lands exactly on that slice. The visual is a presentation of the result, never the source of it.

2. Use crypto randomness, not Math.random.
Math.random is fine for confetti. For a result people act on, the picker uses crypto.getRandomValues to draw the winning index, which gives an unbiased integer in the entry range. With weighted entries, the draw runs over the total weight and walks the cumulative weights to find the slice.

3. Let readers test the fairness themselves.
Every tool page ships a "Check the fairness yourself" panel that runs 1,000 test draws against the current entries and prints the count per entry with the expected range. When I ran it on the letter wheel this week, the counts landed between 23 and 47 per letter over 1,000 spins — wide, honest variance around the expected 38.5, and the panel says so.

The rest of the stack is deliberately plain: one WordPress plugin renders each tool from a static fragment, state (entries, counts, settings) persists in localStorage only, and nothing about a spin ever leaves the device. Pages are static HTML with inline SVG, which keeps the wheel usable on slow school and office networks.

If you build random tools, I would push on one point: publish your fairness test next to the tool, not in a blog post nobody finds. A spinner people can audit beats a spinner people are asked to trust.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.