Leads in Coin Tossing

Manipulate[SeedRandom[sr];
y=Which[n==10, 5,n==100,15,n==1000, 50, n==10000, 220];list=Accumulate[RandomChoice[{-1,1},{n}]];ListLinePlot[list, AxesOrigin -> {1, 0},Axes->{True, False}, Filling->Axis, PlotRange -> {{0, n}, {-y, y}}, Ticks -> None,
PlotLabel->Style[Column[{ "percent of time in the lead",Row[{"heads = ",N[100 (Count[ Part[list,Flatten[Position[list, 0]-1]],x_/;x≥0] +Count[list,x_/;x>0])/Length[list]] }],
Row[{"tails = ",N[100 ( Count[ Part[list,Flatten[Position[list, 0]-1]],x_/;x<=0]+Count[list,x_/;x<0])/Length[list]]}]
}],"Label"],ImageSize->{450,300}],{{n,10000,"number of tosses"},{10,100,1000,10000}},
{{sr,123,"random seed"},1,12345,1},TrackedSymbols:>{n,sr}]

Consider a game in which a fair coin is tossed repeatedly. When the cumulative number of heads is greater than the cumulative number of tails, heads is in the lead. Tails moves to the lead when the cumulative number of tails is greater than the cumulative number of heads. Intuition might suggest that with a large number of coin tosses, heads and tails would spend roughly equal time in the lead. In fact, it is much more likely that one side or the other will be lucky a high proportion of the time. When the blue line is above the horizontal, heads is in the lead; when it is below, tails is in the lead.  Vary the random seed and observe how often one side or the other is in the lead close to 100% of the time.

W. Feller, "Fluctuations in Coin Tossing and Random Walks", An Introduction to Probability Theory and Its Applications, Vol. 1, New York: John Wiley & Sons, Inc., 1950 pp. 67-97.

Contributed by: Fiona Maclachlan