Technical challenges
The core challenge was making a weighted random draw feel fair and trustworthy: the winner has to be selected correctly according to each prize's configured weight, the spin animation has to visually land on that exact result without looking ambiguous, and a rapid double-tap or an accidental back-press during the result dialog must never be able to record two results for one spin.
How I approached it
The winner is selected first, using cumulative-weight random sampling — not a naive equal-chance pick — before any animation runs. The wheel's visual slices are deliberately equal in size regardless of weight, so probability and visual layout stay decoupled; a separate geometry calculation then computes the spin's landing rotation, with a safety margin that nudges the stop point away from a slice boundary so the result never looks ambiguous. Saving or skipping a result after the spin is guarded by a single-flight state check, confirmed with a dedicated concurrency test, so at most one history record can ever result from one spin.


