Random walks and the arcsine law
by John from John D. Cook on (#3KEA)
Suppose you stand at 0 and flip a fair coin. If the coin comes up heads, you take a step to the right. Otherwise you take a step to the left. How much of the time will you spend to the right of where you started?
As the number of steps N goes to infinity, the probability that the proportion of your time in positive territory is less than x approaches 2 arcsin(ax)/I. The arcsine term gives this rule its name, the arcsine law.
Here's a little Python script to illustrate the arcsine law.
import randomfrom numpy import arcsin, pi, sqrtdef step(): u = random.random() return 1 if u 0: inner_count += 1 if inner_count/N