Gambler's Ruin
A gambler starts with units and bets 1 unit at a time, winning with probability and losing with probability . They stop when they reach a target or go broke. What is the probability of ruin, and how long does the game last? The answers explain why casinos win, why "just one more bet" is dangerous, and how random walks with barriers behave.
Ruin probability
Let be the probability of ruin starting from . First-step analysis gives with and , a linear recurrence. Its solution:
In a fair game, the probability of doubling your money from to is exactly , and the probability of reaching is : your chance of winning is proportional to your share of the total money.
Small edges, big effects
With even a slight disadvantage, the odds of reaching a distant target collapse. Betting on red in American roulette (), starting with 100 units:
def ruin(k, N, p):
q = 1 - p
if p == q:
return 1 - k / N
r = q / p
return (r ** k - r ** N) / (1 - r ** N)
for p, name in [(0.5, "fair coin"), (18 / 37, "European roulette"), (18 / 38, "American roulette")]:
print(f"{name:18s}: P(reach 110 from 100) = {1 - ruin(100, 110, p):.4f} "
f"P(reach 200 from 100) = {1 - ruin(100, 200, p):.6f}")fair coin : P(reach 110 from 100) = 0.9091 P(reach 200 from 100) = 0.500000
European roulette : P(reach 110 from 100) = 0.5813 P(reach 200 from 100) = 0.004466
American roulette : P(reach 110 from 100) = 0.3487 P(reach 200 from 100) = 0.000027
A nearby target such as 110 is still reachable in roulette (58% in the European game, 35% in the American one), because luck matters a lot over a few hundred bets. Doubling the money is almost impossible: over the thousands of bets it takes, the house edge wins. For a gambler facing a casino with practically unlimited money (), ruin is certain whenever .
Strategy: bold play
If you must reach a target in an unfavourable game, betting big is better than betting small: fewer bets give the house edge fewer chances to act. Compare betting 1 unit at a time with betting everything (or as much as needed) each time:
import random
rng = random.Random(4)
p, start, target, runs = 18 / 38, 50, 100, 20_000
def timid():
x = start
while 0 < x < target:
x += 1 if rng.random() < p else -1
return x == target
def bold():
x = start
while 0 < x < target:
bet = min(x, target - x)
x += bet if rng.random() < p else -bet
return x == target
print("timid (1 unit per bet):", sum(timid() for _ in range(runs)) / runs)
print("bold (bet what is needed):", sum(bold() for _ in range(runs)) / runs, " (one bet: p =", round(p, 4), ")")timid (1 unit per bet): 0.0052
bold (bet what is needed): 0.47685 (one bet: p = 0.4737 )
Starting at 50 with a target of 100, bold play is a single bet with probability ; timid play succeeds with probability about 0.005.
Duration of the game
The expected number of bets satisfies with . In the fair case the solution is : starting with 50 units against a target of 100, the game lasts 2500 bets on average. This matches the absorbing chain computation of expected absorption times.
import random
rng = random.Random(5)
def duration(k, N):
x, t = k, 0
while 0 < x < N:
x += rng.choice((-1, 1))
t += 1
return t
for k, N in [(5, 10), (10, 20), (25, 50)]:
runs = 5000
avg = sum(duration(k, N) for _ in range(runs)) / runs
print(f"k={k}, N={N}: simulated {avg:.1f} k(N-k) = {k * (N - k)}")k=5, N=10: simulated 25.3 k(N-k) = 25
k=10, N=20: simulated 102.4 k(N-k) = 100
k=25, N=50: simulated 626.1 k(N-k) = 625
In software
The gambler's ruin is the model behind risk-of-ruin calculations in trading and insurance, the analysis of TCP-like protocols that random-walk a window size between limits, and the random-walk algorithm for 2-SAT, whose expected running time is bounded with exactly the duration formula (Randomized Algorithms).
Exercises
Exercise 1: Fair game
In a fair game, you start with 30 and stop at 0 or 100. What is the probability of reaching 100, and the expected number of bets?
Answer
; bets.
Solution
and .
Exercise 2: Favourable game
With , starting from 2, what is the probability of reaching 5 before going broke?
Answer
About .
Solution
, and . So and the success probability is .
Exercise 3: Check by simulation (code)
Simulate Exercise 2 and compare with the formula.
Answer
Both near 0.640.
Solution
import random
rng = random.Random(6)
def reach(k, N, p):
while 0 < k < N:
k += 1 if rng.random() < p else -1
return k == N
runs = 100_000
q_over_p = 0.4 / 0.6
exact = 1 - (q_over_p ** 2 - q_over_p ** 5) / (1 - q_over_p ** 5)
print(round(sum(reach(2, 5, 0.6) for _ in range(runs)) / runs, 4), round(exact, 4))0.6359 0.6398
Test yourself
In a fair game starting with and stopping at 0 or , the probability of reaching is…
- 1/2
In an unfavourable game where you must reach a target, which strategy maximises the success probability?
- Small bets
- Bold play (large bets)
- Alternating bets
- It does not matter