Skip to main content
EDINBURGH KILN WORKSHOP Free Virtual Kiln Beads · Zero Monetary Value
Open Pot 30,000 KB
  1. Hearth
  2. Kiln Notes
  3. Rejection Sampling and Web Crypto: Honest Randomness in One Browser Tab
Maths & RNG Published 2026-11-24 5 min read By Fiona MacLeod

Rejection Sampling and Web Crypto: Honest Randomness in One Browser Tab

A plain-English engineering walkthrough of why Bowbell Sound avoids Math.random() and how window.crypto.getRandomValues powers every reel stop and dice cast.

Many casual browser games quietly rely on JavaScript's built-in Math.random() function. While Math.random() is fast for particle effects or confetti, it was never designed for transparent probability simulations: its underlying pseudo-random sequence varies between browser engines and offers weak statistical guarantees across long runs. At Bowbell Sound, every single reel stop, mystery shroud reveal, casket draw, and Kiln Cast 1–100 roll uses the Web Cryptography API via window.crypto.getRandomValues().

Even with a cryptographically strong random source, a subtle programming bug called modulo bias can sneak into naive implementations. Suppose a virtual reel strip contains 36 stops and a developer draws an unsigned 8-bit integer between 0 and 255, then calculates value % 36. Because 256 does not divide evenly by 36 (36 × 7 = 252, leaving a remainder of 4), the first four stops—indices 0, 1, 2, and 3—would appear slightly more often than stops 4 through 35.

To eliminate modulo bias completely, our ES6 Core engine applies rejection sampling on 32-bit unsigned integers. Given a target range N, we compute the largest multiple of N that fits below 2^32. Any drawn integer falling into the small upper remainder zone is discarded and redrawn immediately in microseconds. The result is mathematically uniform selection over every stop on every reel strip, and over every integer from 1 to 100 on our Kiln Cast bench.

Equally important is independence. Each spin in Bowbell Sound has zero memory of the spin before it. Your guild rank—whether Clay Sifter or Master Bell-Founder—never nudges a reel strip. Your current Kiln Bead balance, the time of day, and whether you play on a Night Pass or a full local Bench Account have zero input into the stop selector. Streaks happen naturally in true uniform randomness; when you see three quiet spins followed by a bright cascade, that is ordinary variance at work rather than scripted drama.

Because everything executes locally inside your browser without a remote betting server, you can even open browser developer tools and inspect kit/behavior/bbs-core.js line by line. Transparency is the best antidote to superstition: once you see how clean rejection sampling works, every spin becomes a relaxed, verifiable piece of craft.

← All Kiln Notes Test the 20 Kilns Open Clay Lexicon

Further Reading from the Almanac