🎲 Gambler's Ruin
Simulate the classic gambler starting with k dollars betting against a house of n dollars. Discover why the house always wins with interactive ruin probability charts.
About this simulation
This simulator explores the classic Gambler's Ruin problem: a gambler with starting capital k bets $1 per round against a house, winning with probability p, stopping only at $0 (ruin) or target n (success). It's a one-dimensional random walk with two absorbing barriers and an exact closed-form ruin probability. Four modes let you watch one walk, batch trials against theory, plot ruin curves for several p values, or explore stake sizing with the Kelly criterion.
🔬 What it shows
Path walk animates a single random walk between the 0 and n barriers. Multi-trial batches many walks and compares simulated ruin percentage with theory. Theory curve plots P(ruin) against k for five win probabilities (0.35–0.65), highlighting your chosen p. Kelly sizing plots log-growth rate g(f) against stake fraction f, marking the optimal Kelly fraction f* with a green dot.
🎮 How to use
Set Win probability p (0.30–0.70), Starting capital k (1–99) and Total wealth n (10–200); k is kept below n automatically. Trials (10–1000) sets the batch size in Multi-trial mode, and Odds b (0.5–5) sets the payout per $1 wagered in Kelly sizing mode. Pause, Reset and Run new trial control the animation.
💡 Did you know?
The gambler's ruin problem was posed as one of five exercises in Christiaan Huygens' 1657 treatise on probability, one of the earliest books on the subject, and wasn't fully solved in closed form until later work by Bernoulli and de Moivre.
Frequently asked questions
What do the four view modes show?
Path walk animates a single walk between the 0 and n barriers. Multi-trial batches walks (eight per frame) and compares simulated versus theoretical ruin percentage. Theory curve plots P(ruin) against k for five win probabilities. Kelly sizing instead plots log-growth rate against stake fraction f.
Why can't starting capital k reach or exceed total wealth n?
k is the gambler's stake out of a fixed total n, so it must stay below n for the walk to have somewhere to go; the simulator automatically clamps k to n − 1 if the sliders would push it past n.
Why is the win probability slider limited to 0.30–0.70?
p is the chance of winning each $1 bet. Values near 0 or 1 make the outcome almost certain within a few rounds, flattening the theory curves and multi-trial statistics into uninformative straight lines.
What does the odds slider b change in Kelly sizing mode?
b is the net payout per $1 wagered, used in the growth formula g(f) = p·ln(1+bf) + q·ln(1−f). Raising b increases the optimal Kelly fraction f* = p − q/b; if p is at or below 0.5 the mode reports there is no edge.
How closely does the simulated ruin percentage match the theoretical formula?
Multi-trial mode tallies how many of its batched walks end at 0 versus n. As trials grow, the simulated ruin percentage converges toward the exact formula — 1 − k/n for a fair game, or the (q/p)^k ratio for a biased one — by the law of large numbers.
Frequently Asked Questions
-
What is the Gambler's Ruin problem?The Gambler's Ruin is a classic probability problem: a gambler starts with k dollars and bets $1 per round against an opponent (the house) with n − k dollars. The game ends when one player reaches $0. The question is: what is the probability the gambler is ruined before winning?
-
What is the ruin probability for a fair game?For a fair coin flip (p = q = 0.5), the ruin probability for a gambler starting with k dollars when total wealth is n is P(ruin) = 1 − k/n. So if you have $10 out of $100 total, you have a 90% chance of going broke.
-
What is the ruin probability for a biased game?For a biased game where you win each round with probability p and lose with q = 1 − p, the ruin probability is P(ruin) = (1 − (q/p)^k) / (1 − (q/p)^n). When p < 0.5 (house edge), this quickly approaches 1 even for large starting capital.
-
Why does the house always win?Casinos maintain a small house edge (e.g. p = 0.493 in roulette). Even a tiny bias makes the ruin probability for the gambler approach 1 as the number of rounds grows. The casino's much larger capital means the effective ratio k/n is always tiny for any individual player.
-
What is the Kelly Criterion?The Kelly Criterion gives the optimal fraction f* = p − q/b of your bankroll to bet per round, where b is the odds received (net payout per $1 wagered). Betting the Kelly fraction maximises the long-run growth rate of your bankroll and minimises the risk of ruin.
-
What is the expected duration of the game?For a fair game starting at k with total wealth n, the expected number of rounds until the game ends is k(n−k). For a biased game with p ≠ 0.5, the expected duration depends on both the win probability and the ratio q/p.
-
How does starting capital affect ruin probability?In a fair game, ruin probability is exactly (n − k)/n: doubling your starting capital halves your ruin probability. In a biased game the effect is much stronger — even doubling k barely reduces ruin probability when there is a house edge, because the (q/p)^k term dominates.
-
What happens when p > 0.5?When you have a genuine edge (p > 0.5), the ruin formula gives a ruin probability less than 1 even against an infinitely rich opponent. For example with p = 0.55 starting at k=10 of n=100, the ruin probability drops substantially compared to the fair game.
-
Is the Gambler's Ruin related to random walks?Yes — each game is a 1D random walk on the integers {0, 1, …, n} with absorbing barriers at 0 and n. The gambler's wealth at time t is a Markov chain, and the ruin probability is the absorption probability at state 0 starting from state k.
-
What real-world situations follow the Gambler's Ruin model?Beyond casinos, the model applies to: stock trading with a fixed strategy, species extinction risk in ecology (population reaching 0), insurance ruin theory, clinical trials (drug 'beating' placebo), and packet collision in network protocols. Any finite-resource competition against a better-capitalised opponent follows similar dynamics.
Set stake, target and win probability, then run Monte Carlo random walks to see how often the gambler goes broke before reaching the goal.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install