Room for ChanceThe science of chance

Random number generators

How RoomForChance Generates Random Numbers: An Inspectable Method

An implementation-level explanation of RoomForChance’s browser random source, rejection sampling, partial shuffle and separate simulation methodology.

RoomForChance · 3 min read · Published · How this work was prepared

RoomForChance's game-selection code uses the browser's crypto.getRandomValues facility, converts its unsigned 32-bit values into bounded integers with rejection sampling, and uses those integers to select from the relevant pools. The core source is available in the site's random.js module. This guide describes the inspected implementation, not a third-party security certification.

The purpose is impartial selection according to a game's rules. It is not prediction of the external draw.

The bounded-integer function The randomInt function accepts an integer limit between 1 and 2^32. It computes ceiling = floor(2^32/limit)×limit, obtains an unsigned 32-bit word, and retries while the word is at least that ceiling. It returns the accepted word modulo the limit.

Under a uniform word source, every result from zero through limit−1 has the same number of accepted preimages. This is the mathematical reason for the rejection step. Simply applying modulo without rejecting the surplus would be biased whenever the limit does not divide 2^32.

Selecting distinct main labels The choose function constructs the pool 1 through max and performs the first count steps of a Fisher–Yates-style shuffle. At step i, it selects uniformly from the remaining positions and swaps that value into position i. It then takes the selected prefix and sorts it for display.

The partial shuffle gives each ordered distinct selection the same probability. Every unordered set has the same number of orders, so sorting preserves uniformity over the sets. It changes presentation, not the selected membership.

One million outputs per method, using a deliberately small eight-bit source range. Modulo assigns four faces 43 byte values and two faces 42; rejection accepts 252 values divided equally among six faces. The bars show samples, the reference line shows 1/6.
Figure 1. One million outputs per method, using a deliberately small eight-bit source range. Modulo assigns four faces 43 byte values and two faces 42; rejection accepts 252 values divided equally among six faces. The bars show samples, the reference line shows 1/6.

Game rules add necessary structure Different games can have separate extra pools, ordered digits, optional features or user-fixed labels. The relevant game configuration and generation branch determine which model applies. A main label and a separately pooled special label may share a numeral; an ordered digit game may allow repeated digits.

When a user locks labels manually, the generator fills the remaining places from eligible labels. That is a conditional selection containing the locked choices, not an unrestricted sample over all lines. It does not improve the full-match probability of the resulting specified line.

What is not claimed The code does not read past results to assign predictive scores. A repeated complete line is possible on separate generation requests. A secure browser source does not guarantee a win, prove every device's implementation flawless or make the site an official lottery operator.

If the required cryptographic facility is unavailable, the inspected bounded-integer function does not silently substitute Math.random. Error handling belongs to the calling interface. This is an implementation observation, not a promise about every possible future version.

Why the Lab uses a different random stream Published experiments need replayable results. They use NumPy PCG64 with recorded seeds and software versions, while browser demonstrations identify their own seeded simulation method. Those are labelled pseudorandom simulations and are not security-token generators.

Readers can inspect the game source, download the Lab program and compare the exact formulas with the observed data. Transparency means stating the scope of each component clearly: the browser picker makes a choice, the simulation studies a model, and the mathematics explains the probability assigned by that model.

Leave the selection to chance

If you want a valid random game line, open the relevant generator. A generated line is not an official entry or a prediction, and it does not improve the probability of a specified valid combination.

Sources and further reading

The worked examples and derivations are RoomForChance explanations. Operator sources establish game parameters; research sources support the specific points identified above. University links are references, not endorsements.

  1. RoomForChance · Game generator sourceInspect randomInt, choose and the game-specific branches. This is implementation transparency, not an external certification.
  2. W3C · Web Cryptography Level 2API specification; the linked Level 2 document is a working draft. The source contract and the application mapping are separate layers.
  3. Joe Blitzstein and Jessica Hwang · Harvard Stat 110 / Introduction to ProbabilityUniversity-level further reading on counting, conditioning and probability models.

Continue the argument

Random Number Generators: From Entropy to a Fair Choice
Understand how random number generators combine a source, an algorithm and a mapping—and why each stage matters for fair lottery selections.

Modulo Bias Explained: Why a Random Byte Makes an Unfair Die
See the exact 256-to-6 mapping behind modulo bias, calculate the imbalance, and understand how rejection sampling removes it.

How to Generate Random Numbers Without Repetition
Learn two fair methods for distinct random numbers, why sorting is safe, and why filtering patterns changes the distribution.