TExcelTAD
Home › Probability Theory › Gambler's Ruin

Gambler's Ruin

A gambler starts with kk units and bets 1 unit at a time, winning with probability pp and losing with probability q=1−pq = 1 - p. They stop when they reach a target NN 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 rkr_k be the probability of ruin starting from kk. First-step analysis gives rk=p rk+1+q rk−1r_k = p\,r_{k+1} + q\,r_{k-1} with r0=1r_0 = 1 and rN=0r_N = 0, a linear recurrence. Its solution:

rk={(q/p)k−(q/p)N1−(q/p)Np≠q1−kNp=q=12r_k = \begin{cases} \dfrac{(q/p)^k - (q/p)^N}{1 - (q/p)^N} & p \ne q \\[2ex] 1 - \dfrac{k}{N} & p = q = \tfrac{1}{2} \end{cases}

In a fair game, the probability of doubling your money from kk to 2k2k is exactly 1/21/2, and the probability of reaching NN is k/Nk/N: 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 (p=18/38p = 18/38), starting with 100 units:

python · try it yourself
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 (N→∞N \to \infty), ruin is certain whenever p≤1/2p \le 1/2.

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:

python · try it yourself
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 18/38≈0.47418/38 \approx 0.474; timid play succeeds with probability about 0.005.

Duration of the game

The expected number of bets DkD_k satisfies Dk=1+pDk+1+qDk−1D_k = 1 + pD_{k+1} + qD_{k-1} with D0=DN=0D_0 = D_N = 0. In the fair case the solution is Dk=k(N−k)D_k = k(N - k): 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.

python · try it yourself
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 k(N−k)k(N - k) 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

0.30.3; 30⋅70=210030 \cdot 70 = 2100 bets.

Solution

k/N=30/100k/N = 30/100 and Dk=k(N−k)D_k = k(N - k).

Exercise 2: Favourable game

With p=0.6p = 0.6, starting from 2, what is the probability of reaching 5 before going broke?

Answer

About 0.6400.640.

Solution

q/p=2/3q/p = 2/3, (2/3)2≈0.4444(2/3)^2 \approx 0.4444 and (2/3)5=32/243≈0.1317(2/3)^5 = 32/243 \approx 0.1317. So r2=0.4444−0.13171−0.1317≈0.360r_2 = \frac{0.4444 - 0.1317}{1 - 0.1317} \approx 0.360 and the success probability is 1−r2≈0.6401 - r_2 \approx 0.640.

Exercise 3: Check by simulation (code)

Simulate Exercise 2 and compare with the formula.

Answer

Both near 0.640.

Solution
python · try it yourself
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 kk and stopping at 0 or NN, the probability of reaching NN is…

  1. 1/2
  2. k/Nk/N
  3. 1−k/N1 - k/N
  4. (k/N)2(k/N)^2

In an unfavourable game where you must reach a target, which strategy maximises the success probability?

  1. Small bets
  2. Bold play (large bets)
  3. Alternating bets
  4. It does not matter