This is a simulation of simple random walk, including the Gambler's Ruin problem. (If you have trouble running the applet, see these notes.)

[Oops, your browser will not display java applets.]

This applet simulates a gambler who repeatedly bets \$1, either forever (for random walk), or until he either loses by going broke or wins by doubling his initial fortune (for Gambler's Ruin). The probability of victory in the Gambler's Ruin game is known to be

[((1-p)/p)^(Init) - 1] / [((1-p)/p)^(Target) - 1]
(where p is the win probability of each individual bet, Init is the initial fortune, and Target is the target fortune). This is very small if p < 0.5 and I is large. [If p = 0.5 then this formula does not apply; in that case the probability is simply Init/Target.]

The applet accepts the following keyboard inputs. (You may need to "click" on the applet first.)

• Use the numbers '0' through '9' to set the animation speed level higher or lower.
• Use 'r' to restart the simulation, or 'z' to zero the Win/Loss counts.
• Use 'g' to toggle between gambler's ruin mode, and full random walk mode (starting at zero).
• Use '>' and '<' to increase/decrease the win probability of each bet. (Possible values include 0.492929 [the probability of winning at craps] and 0.473684 [the probability of winning at roulette] plus various other values like 0.333333, 0.4, 0.45, 0.49, 0.495, 0.499, 0.4999, 0.5, 0.51, and 0.6.)
• Use '+' and '-' to increase/decrease Init by \$1 (and restart). Or, use 'T' or 'H' or 'G' or 'F' to set Init to \$1 or \$10 or \$100 or \$500, respectively, with Target equal to twice Init.