Back to Tools CSPRNG PRO

1, 2 or 3 Random Number Generator & Ternary Decision Engine

Generate an unbiased 1, 2, or 3 outcome using hardware-grade Web Crypto rejection sampling. Customize option names, run 10,000-trial Monte Carlo simulations, and verify fairness with Pearson’s Chi-Square and Shannon entropy.

Label Presets:
1
2
3
1
Option 1
window.crypto.getRandomValues() · Rejection Limit 4,294,967,295 (0.000000% Modulo Bias)
⚡ Monte Carlo Batch Roll Simulator:

📊 Live Ternary Distribution, Chi-Square (χ²) & Shannon Entropy

Total Rolls: 1
#1 (Option 1) 1 (100.0%)
100.00%
Theoretical: 33.33% (1/3)
#2 (Option 2) 0 (0.0%)
0.00%
Theoretical: 33.33% (1/3)
#3 (Option 3) 0 (0.0%)
0.00%
Theoretical: 33.33% (1/3)
Pearson Chi-Square (df=2)
χ² = 2.000 (p = 0.368)
Shannon Entropy (H)
0.0000 / 1.5850 bits
Sample Mean (μ = 2.000)
1.0000
Longest Streak
1× (#1)
1

Ternary (Base-3) Probability, Streak & Information Entropy Reference Table

Exact mathematical combinatorics for uniform discrete 3-outcome trials (p = 1/3, q = 2/3, H = log₂(3) ≈ 1.58496 bits per trit):

Trial Count (N) State Space (3ᴺ) Identical Streak / Expected Shannon Information Binomial Std Dev (σ) Statistical Interpretation
1 Roll (Single Trial) 3¹ = 3 33.3333% (1 in 3) 1.5850 bits (1 Trit) ±0.471 Single unbiased ternary decision (p = 1/3 each)
2 Rolls (Pair) 3² = 9 11.1111% (1 in 9) 3.1699 bits (2 Trits) ±0.667 Probability of rolling the exact same number twice in a row
3 Rolls (Triplet) 3³ = 27 3.7037% (1 in 27) 4.7549 bits (3 Trits) ±0.816 Probability of a 3-of-a-kind streak (e.g., 1-1-1)
5 Rolls (Sequence) 3⁵ = 243 0.4115% (1 in 243) 7.9248 bits (5 Trits) ±1.054 5 consecutive identical outcomes
100 Rolls (Sample) 3¹⁰⁰ ≈ 5.15×10⁴⁷ Expected: 33.3 ± 4.7 158.50 bits ±4.714 95% confidence interval: 24 to 43 occurrences per number
1,000 Rolls (Monte Carlo) 3¹⁰⁰⁰ Expected: 333.3 ± 14.9 1,584.96 bits ±14.907 95% confidence interval: 304 to 363 occurrences per number
10,000 Rolls (Asymptotic) 3¹⁰⁰⁰⁰ Expected: 3,333.3 ± 47.1 15,849.63 bits ±47.140 Law of Large Numbers converges within ±0.92% of 33.33%

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:

4,294,967,296 = (3 × 1,431,655,765) + 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:

P(X = 1) = P(X = 2) = P(X = 3) = 1⁄3 = 33.3%

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)2

Because 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 / 2

When χ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%.

Frequently Asked Questions About Generating 1, 2, or 3 Randomly

Why does standard Math.random() or modulo % 3 have a mathematical bias?

A 32-bit unsigned integer contains 2³² = 4,294,967,296 possible states. Because 4,294,967,296 is not evenly divisible by 3 (4,294,967,296 = 3 × 1,431,655,765 + 1), a naive u32 % 3 calculation maps one extra integer to remainder 0. Our engine eliminates this modulo bias completely using rejection sampling: any 32-bit value >= 4,294,967,295 is discarded and redrawn via window.crypto.getRandomValues(), guaranteeing an exact 1/3 (33.333333%) probability for 1, 2, and 3.

What is a "Trit" and why does a 1-2-3 generator produce 1.5850 bits of entropy?

Just as a binary coin flip (0 or 1) produces 1 bit (log₂(2) = 1.0000 bit) of Shannon information entropy, an unbiased 3-way ternary decision (1, 2, or 3) produces 1 "trit" (trinary digit) of entropy, equal to log₂(3) ≈ 1.5849625 bits per roll.

What is the probability of rolling the same number (1, 2, or 3) multiple times in a row?

Because each cryptographic draw is statistically independent, the probability of rolling a specific number k times in a row is (1/3)^k. However, the probability that ANY of the three numbers appears k times consecutively is 3 × (1/3)^k = (1/3)^(k-1): 33.33% for a pair (2 in a row), 11.11% for a triplet (3 in a row), and 1.23% for 5 in a row.

How do I interpret the Pearson Chi-Square (χ²) and p-value in the live statistics panel?

Pearson’s Chi-Square test (χ² = Σ (Observed - Expected)² / Expected) measures how closely your session rolls match the theoretical 1/3 uniform distribution with 2 degrees of freedom (df = 3 - 1 = 2). For df = 2, the exact p-value is e^(-χ²/2). A p-value above 0.05 (which corresponds to χ² < 5.991) confirms that any deviation from 33.33% is normal random variance.

Can I use this 1-2-3 generator for Rock-Paper-Scissors or the Monty Hall problem?

Yes! Click the "Rock / Paper / Scissors" or "Monty Hall Doors 1-2-3" preset chips at the top of the tool, or type your own custom names into the three option boxes. Every roll will display both the winning number (1, 2, or 3) and your custom label.

Why are the percentages not exactly 33.33% after 10 or 50 rolls?

In small samples, binomial standard deviation σ = √(N × (1/3) × (2/3)) = √(2N)/3 is relatively large compared to N. After 10 rolls, a 40%–50% share for one number is completely normal. Click the "+1,000" or "+10,000" Monte Carlo buttons to watch the Law of Large Numbers pull all three bars tightly toward 33.33%.