1. The Problem with Weak Randomness on the Web
The vast majority of online spinner and dice websites rely on JavaScript's standard Math.random() method. While perfectly acceptable for cosmetic animations (such as floating confetti particles or randomized star twinkling), it is fundamentally unfit for fair raffles, gaming, or dispute resolution.
Math.random() is a pseudo-random number generator (PRNG) typically powered by algorithms like xorshift128+. These algorithms compute each successive number based on the internal state of the previous one. If an observer collects a modest sequence of past outputs, the generator's internal state can be mathematically reverse-engineered, rendering future outcomes predictable.
"For a school giveaway, a contest, or a tabletop roll, a predictable generator destroys the fundamental foundation of fairness."
2. Our Solution: The Web Cryptography API (CSPRNG)
On Wheel Spinner, we completely replaced Math.random() with the W3C standard cryptographic interface: window.crypto.getRandomValues().
This method hooks directly into the host operating system's cryptographic entropy subsystem (such as /dev/urandom on Linux, macOS, and Android, or BCryptGenRandom on Windows). The entropy originates not from repetitive mathematical loops, but from true physical hardware phenomena:
- Thermal fluctuations and processor clock jitters in your CPU.
- Nanosecond-precision timings of hardware interrupts and disk read/write events.
- Ambient system noise from network controllers and input peripherals.
3. The Danger of "Modulo Bias" and How We Eliminate It
Even when utilizing cryptographic entropy, many online tools commit a major mathematical error when constraining large integers to a specific range using the remainder operator (modulo %).
An unsigned 32-bit integer encompasses $2^32 = 4,294,967,296$ possible states (from 0 to $4,294,967,295$). If you want a number between 1 and 6 for a die and calculate buffer[0] % 6, an imbalance arises: $4,294,967,296$ does not divide evenly by 6 (leaving a remainder of 4).
Consequently, the numbers 0, 1, 2, and 3 have exactly one additional possibility of being rolled compared to 4 and 5. Over millions of rolls, this introduces an uneven statistical slant.
To achieve absolute statistical purity, we implement rejection sampling: we determine the highest exact multiple of the requested range that fits within $2^32$ and discard any random value that falls into the surplus remainder, drawing a fresh cryptographic sample immediately. This guarantees an exact 0.000000% modulo bias.
4. Auditable Open Source Implementation
Below is the exact TypeScript implementation that your browser executes for every wheel spin, coin toss, and dice roll across this website:
/**
* Wheel Spinner - Rejection Sampling Algorithm (Zero Modulo Bias)
* Guarantees 100% uniform probability between min and max.
*/
function getRandomInt(min, max) {
const range = max - min + 1;
const buffer = new Uint32Array(1);
// Maximum valid threshold evenly divisible by range in 32-bit integer space (0 to 2^32 - 1)
const maxValid = 0x100000000 - (0x100000000 % range);
let rawValue = 0;
do {
// True hardware cryptographic entropy from the operating system
window.crypto.getRandomValues(buffer);
rawValue = buffer[0];
} while (rawValue >= maxValid); // Rejects values causing modulo bias
return min + (rawValue % range);
}5. Technical Comparison: Math.random() vs. Wheel Spinner
| Technical Parameter | Standard Websites | Wheel Spinner (Cryptographic) |
|---|---|---|
| Base generator | Standard Math.random() | window.crypto.getRandomValues() |
| Entropy source | System clock / internal seed state | OS hardware entropy (CPU thermal noise /dev/urandom) |
| Predictability | Predictable once prior states are observed | Cryptographically unpredictable (CSPRNG) |
| Modulo bias | Common (direct % range usage) | Zero modulo bias (rejection sampling) |
| Bit resolution | Limited to ~32 bits approximation | Full 53-bit IEEE 754 precision entropy |
| Auditable in F12 DevTools | Difficult to verify fairness | 100% open and verifiable in your browser |
6. Zero Server Communication: 100% Client-Side Privacy
On platforms where outcomes are calculated on a remote backend server via AJAX or WebSocket requests, participants have no way of knowing whether the host server favored a particular user ID or manipulated the results.
On Wheel Spinner, the entire calculation executes 100% inside your local device's memory. In fact, you can disconnect your internet connection entirely after loading the page, and the wheels, coins, and dice will continue to function with identical cryptographic precision. Your lists, names, and selections are never uploaded or transmitted to any external server.