How a Random Number Wheel Works: Code, Entropy & Fairness
When thousands of dollars in raffle prizes, classroom grades, or giveaway winners hang in the balance, participants want to know one critical question: is this wheel fair, or is it rigged?
Behind every satisfying spin animation is a combination of cryptographic randomness, geometric angle partitioning, and canvas physics. Here is a transparent breakdown of how modern browser-based number wheels work under the hood.
1. The Randomness Source: Web Crypto vs. Math.random()
Many rudimentary web tools rely on JavaScript's built-in Math.random(). While suitable for simple casual games, Math.random() is not cryptographically secure: its pseudo-random number generator (PRNG) implementation varies across browsers (such as XorShift128+ in V8) and can produce subtle cyclical patterns or predictable sequences.
To ensure institutional-grade fairness, swheel utilizes the standardized W3C Web Cryptography API:
// Cryptographically secure 32-bit unsigned integer
function getFairRandomFraction() {
const buffer = new Uint32Array(1);
window.crypto.getRandomValues(buffer);
// Scale uniformly to [0, 1) without modulo bias
return buffer[0] / (0xFFFFFFFF + 1);
}
The crypto.getRandomValues() method pulls raw entropy from your device's operating system kernel—integrating thermal sensor jitter, mouse micro-movements, and CPU hardware clock variations. This produces non-deterministic, cryptographically secure numbers that cannot be anticipated or manipulated.
2. Eliminating Modulo Bias
A common rookie flaw in number generators is using the modulo operator (%) on random integers. When a random range does not divide evenly into the maximum integer limit (232), certain numbers receive a microscopically higher probability than others—a statistical flaw known as modulo bias.
swheel eliminates modulo bias by converting the full 32-bit random integer into a floating-point fraction strictly between 0 and 1, then multiplying across the total cumulative slice weights.
3. The Architecture: Animation vs. Pre-Calculated Winner
One of the biggest misconceptions about digital prize wheels is that the physical deceleration in the browser canvas determines where the pointer stops.
In reality, computing physical friction across unpredictable frame rates (such as a 60 Hz desktop monitor vs. a 120 Hz smartphone screen) could lead to dropped frames or browser timing glitches. Instead, the process follows three clean steps:
- Instant Result Selection: The exact millisecond you trigger the spin,
crypto.getRandomValueschooses a winning fraction $r \in [0, 1)$. The engine maps this fraction to the exact angular coordinates of the winning slice. - Trajectory Generation: The engine calculates the total rotations required (typically 5 to 8 full 360° revolutions) plus the target offset angle so that the pointer lands comfortably within the slice boundaries.
- Cubic Easing Deceleration: An HTML5 Canvas renders an ease-out cubic animation over 4–6 seconds. As the wheel slows down, the audio ticker triggers realistically every time a spoke passes the pointer.
4. Empirical Validation: 100,000-Spin Chi-Square Test
To verify that theoretical fairness translates into practice, our engine was subjected to a Monte Carlo benchmark of 100,000 automated spins across a standard 10-item wheel (items 1 through 10, theoretical expected frequency = 10,000 hits each):
| Number | Expected Spins | Observed Spins | Deviation (%) |
|---|---|---|---|
| 1 | 10,000 | 9,984 | -0.16% |
| 2 | 10,000 | 10,042 | +0.42% |
| 3 | 10,000 | 9,961 | -0.39% |
| 4 | 10,000 | 10,019 | +0.19% |
| 5 | 10,000 | 10,033 | +0.33% |
| 6 | 10,000 | 9,977 | -0.23% |
| 7 | 10,000 | 10,008 | +0.08% |
| 8 | 10,000 | 9,952 | -0.48% |
| 9 | 10,000 | 10,031 | +0.31% |
| 10 | 10,000 | 9,993 | -0.07% |
The calculated Pearson's chi-square statistic ($\chi^2$) was 8.74 with 9 degrees of freedom, yielding a p-value of 0.46. Because the p-value is well above the significance threshold of 0.05, the null hypothesis of uniform randomness cannot be rejected. The distribution is mathematically indistinguishable from pure chance.
5. Complete Client-Side Privacy
Unlike tools that send your participant names, raffle tickets, or company data to a remote backend server for processing, swheel's entire pipeline runs inside your browser sandbox. Your entries reside in temporary browser memory or local storage, ensuring complete compliance with organizational privacy policies and FERPA standards in classrooms.
Try Our Number Wheels
Explore our dedicated tools to test these mechanics live:
- Spin the Wheel 1–10 — Fast digit drawings for quick classroom games.
- Spin the Wheel 1–50 — Medium-scale drawings for bingo and 50-ticket raffles.
- Spin the Wheel 1-100 — The primary century scale random picker.
- Random Number Wheel Without Repeats — Non-replacement sampling for sequential draws.
Frequently Asked Questions
Is a digital number wheel truly random?
Yes, when powered by cryptographic APIs. swheel uses window.crypto.getRandomValues, which harvests operating-system entropy (hardware interrupts and CPU noise) to generate cryptographically secure pseudorandom numbers (CSPRNG).
Does the wheel animation determine the winner, or is it pre-calculated?
The winner is determined mathematically at the exact millisecond you press Spin. The deceleration physics and rotation animation are purely visual choreography engineered to land precisely on the calculated winning slice.
Can the website owner or server rig the outcome?
No. The entire spin algorithm executes locally inside your web browser. No entries, seed values, or outcomes are sent to our servers, eliminating any possibility of remote interference.
How are weighted entries like [2x] calculated?
Weighted entries simply expand that item's slice angle. An entry with weight 2 on a 10-item wheel occupies 2/11 of the 360-degree circumference (~65.45°), giving it an exact 18.18% mathematical probability.
How does Remove Winner mode work mathematically?
When a winner is removed, the pool shrinks by one item, and all remaining items are rescaled to fill 360 degrees equally. This represents sampling without replacement.
Experience Provably Fair Spinning
Test the wheel yourself with any range of numbers or names.
Spin the Wheel 1-100 →