Monte Carlo Simulation: How Computers Estimate the Unknowable
Some probability problems are analytically intractable. Monte Carlo simulation solves them by substitution: simulate thousands of trials and count the outcomes.
Some probability problems have exact analytical solutions. The probability of rolling a six on a fair die is 1/6. The probability of being dealt a royal flush in five-card draw is 4/2,598,960. You can derive these from combinatorics with pen and paper.
Other problems are analytically intractable. What is your probability of winning a Texas Hold'em hand when you hold ace-king offsuit, there are two cards on the board, and you are playing against three opponents? The state space is enormous. Monte Carlo simulation solves this by substitution: instead of calculating the probability analytically, you simulate the scenario tens of thousands of times, randomizing all unknowns, and count outcomes.
The basic algorithm
For our Poker Evaluator, the Monte Carlo process runs as follows:
1. Record known cards: your 2 hole cards + visible community cards 2. Build remaining deck: 52 cards minus all known cards 3. For each simulation (repeat 10,000 times): a. Shuffle remaining deck b. Deal remaining community cards from shuffled deck c. Deal 2 hole cards to each opponent from shuffled deck d. Evaluate all hands using 7-card hand ranking e. Record: win, loss, or tie for player 4. Win% = wins / 10,000 Tie% = ties / 10,000 Loss% = losses / 10,000
At 10,000simulations, the result is accurate to within approximately ±1% with 95% confidence. At 100,000 simulations the margin narrows to ±0.3%, but compute time increases proportionally.
Why we use a Web Worker
JavaScript is single-threaded. Running 10,000 iterations of a hand evaluator on the main browser thread would freeze the UI for several seconds. We offload the simulation to a Web Worker — a separate browser thread — and receive a postMessage when results are ready. The interface remains responsive while the simulation runs.
The convergence property
The standard error of the Monte Carlo estimate shrinks proportionally to 1/√n. Halving the error requires quadrupling the sample size. At 10,000 simulations, you have an excellent balance of accuracy and speed for practical pot-odds decisions.
Where Monte Carlo is used outside of games
Today, Monte Carlo simulation is used in financial risk modeling (Value at Risk for bank portfolios), climate modeling (uncertainty in temperature projections), drug trial design (calculating required sample sizes), and engineering (stress testing structural components under variable loads).
The poker evaluator in your browser uses the same fundamental technique as a Goldman Sachs risk model. The underlying mathematics is identical. The inputs and stakes are different.