What This 1, 2, or 3 Generator Does
This tool selects one of three outcomes—1, 2, or 3—with an equal 33.3333% probability using the browser’s hardware random number generator (window.crypto.getRandomValues) and rejection sampling. You can draw single numbers or run batch simulations to observe how a uniform 3-way distribution behaves over large sample sizes.
- Custom option labels and presets: Rename options 1, 2, and 3 to any custom text, or apply one-click presets for 1 / 2 / 3, Rock / Paper / Scissors, Monty Hall Doors 1–2–3, and Gold / Silver / Bronze.
- Single draw and Monte Carlo batch rolls: Generate one outcome at a time (with optional audio feedback and one-click copying) or add +10, +100, +1,000, or +10,000 trials at once.
- Live statistical telemetry: Tracks the exact count and percentage for each of the three outcomes, Pearson’s Chi-Square goodness-of-fit (χ² and p-value for df = 2), Shannon entropy in bits (out of 1.5850 bits), sample mean, longest consecutive streak, and the last 36 draws.
The Mathematics of a True 1, 2, or 3 Generator: Eliminating Modulo Bias
Choosing between three equally likely options—1, 2, or 3—is one of the most fundamental operations in game theory, randomized clinical trial allocation (three-arm trials: Placebo, Low Dose, High Dose), and Monte Carlo simulations. Yet generating a mathematically pure p = 1⁄3 probability on a binary computer is surprisingly subtle.
Every digital processor operates in base-2 (binary). When a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) such as window.crypto.getRandomValues(new Uint32Array(1)) generates a random 32-bit unsigned integer, it selects uniformly from 232 = 4,294,967,296 possible values (0 through 4,294,967,295). Because 2n is never divisible by 3, dividing 4,294,967,296 by 3 leaves a remainder of 1:
If a developer naively writes (randomUint32 % 3) + 1, the outcome 1 receives 1,431,655,766 possible states while outcomes 2 and 3 receive 1,431,655,765 states each. Our engine eliminates this modulo bias via cryptographic rejection sampling: we define the exact multiple threshold L = 3 × 1,431,655,765 = 4,294,967,295. If the hardware entropy pool draws u32 ≥ L, that draw is discarded and immediately re-sampled. Across the remaining 4,294,967,295 valid states, outcomes 1, 2, and 3 each occupy exactly 1,431,655,765 states:
Information Theory: Trits, Shannon Entropy (1.585 Bits), and Discrete Moments
In Claude Shannon’s 1948 mathematical theory of communication, the information entropy $H(X)$ of a discrete random variable X with outcomes {x1, x2, …, xk} is measured in binary bits (shannons):
H(X) = -Σi=1k P(xi) log2 P(xi)For a fair ternary variable X ∈ {1, 2, 3} where P(X = i) = 1⁄3:
- Maximum Theoretical Entropy (1 Trit): Hmax = -3 × (1⁄3 log2 1⁄3) = log2(3) ≈ 1.5849625 bits/symbol In computer science, this fundamental base-3 unit of information is called a trit (trinary digit). Ten independent rolls of our 1-2-3 generator carry 10 × log2(3) ≈ 15.85 bits of entropy, spanning 310 = 59,049 distinct sequences.
- Expected Value (µ) and Variance (σ2): Treating {1, 2, 3} as numerical values, the theoretical population mean is µ = 1 + 2 + 3⁄3 = 2.0000, the population variance is σ2 = (1-2)2 + (2-2)2 + (3-2)2⁄3 = 2⁄3 ≈ 0.6667, and the standard deviation is σ = √2/3 ≈ 0.8165.
Verifying Fairness with Pearson’s Chi-Square (χ2) Goodness-of-Fit Test
How can you mathematically prove that a sequence of N generated numbers is genuinely uniform? Our live telemetry bar continuously computes Pearson’s Chi-Square (χ2) test statistic across the observed counts O1, O2, O3 and the expected count E = N / 3:
χ2 = Σi=13 (Oi - E)2⁄E = 3⁄NΣi=13 (Oi - N⁄3)2Because there are k = 3 categories, the distribution has df = k - 1 = 2 degrees of freedom. Remarkably, the Chi-Square distribution with df = 2 simplifies to an exponential distribution, allowing our engine to compute the exact closed-form p-value without numerical approximation:
p-value = ∫χ2∞ 1⁄2 e-t/2 dt = e-χ2 / 2When χ2 < 5.991$ ($p > 0.05), the empirical distribution passes the standard 95% statistical uniformity test.
Applications in Game Theory: Rock-Paper-Scissors Nash Equilibrium and Monty Hall
A cryptographic 1-or-2-or-3 generator is the ultimate tool for two famous problems in probability and game theory:
- Rock-Paper-Scissors Mixed-Strategy Nash Equilibrium: Human players are notoriously predictable in Rock-Paper-Scissors, subconsciously repeating winners or cycling patterns. Because the game is a symmetric zero-sum matrix, the unique Nash Equilibrium strategy is to select Rock (`1`), Paper (`2`), and Scissors (`3`) with an unexploitable, memoryless (1⁄3, 1⁄3, 1⁄3) CSPRNG distribution.
- The Monty Hall Three-Door Paradox: In a game with Doors `1`, `2`, and `3`, the prize is placed behind one door at random (P = 1/3), and the contestant picks a door (P = 1/3). Because the initial placement is uniform across all three doors, 2/3 of the time the prize lies behind one of the two unchosen doors—proving why switching doors after the host reveals an empty door doubles your winning probability from 33.33% to 66.67%.