Random walks explained

Let someone take a step in a random direction, then another, and another. Where do they end up? Nowhere in particular, on average, and yet they wander further and further away. The random walk is one of the simplest models in probability, and one of the most useful: it describes a molecule in a gas, a share price, a foraging animal and a gambler's fortune.

A thousand random walkers spread out from the centre of a grid, a dozen of their paths drawn in colour, above a histogram of their distances from the start with the Rayleigh curve
A thousand random walkers spread out from the centre of a grid, a dozen of their paths drawn in colour, above a histogram of their distances from the start with the Rayleigh curve

The drunkard's walk

The name comes from a letter to Nature in 1905, in which the statistician Karl Pearson asked how far a man would be from his starting point after n straight stretches in random directions. Lord Rayleigh answered within a week: he had solved the same problem for sound waves in 1880. Pearson concluded that the most likely place to find a drunk man who can still stand is near where he started. That is true, and yet the typical distance keeps growing. Both halves of the answer are what makes the random walk interesting.

Zero on average

On a grid each step is one of left, right, up or down, each with chance 1/4. The step along x is +1, −1 or 0, with expected value 0, and steps are independent, so the expected position after N steps is exactly the start: E[x] = E[y] = 0. Averaged over many walkers, the cloud stays centred on the origin. In the app the mean of all end points sits on the centre within a step or two, whatever the number of steps. The expected value says nothing about how far a single walker gets.

Variance grows with every step

Spread is measured by the variance. One step along x has variance 1/2 on the grid (it is ±1 half of the time), and the variances of independent steps add up, so after N steps Var(x) = N/2 and Var(y) = N/2. The squared distance r² = x² + y² therefore has expected value N: the mean squared distance grows exactly in step with the number of steps. Its square root, the root mean square distance √N, is the typical distance. After 100 steps a walker is about 10 steps away, after 10,000 steps about 100. Four times the walking only doubles the distance.

The Rayleigh curve

By the central limit theorem, after many steps x and y are each close to normal with variance σ² = N/2, and close to independent. The distance r = √(x² + y²) then follows the Rayleigh distribution, with density (r/σ²)·e^(−r²/2σ²). Its peak is at r = σ, it is zero at the start, and its mean is σ√(π/2) ≈ 0.886√N. After 500 steps that is about 19.8 steps, and the histogram of a thousand walkers lands close to it. On a line the position itself is normal with variance N, so the histogram is a bell curve centred on 0.

Coming home

Will a walker ever return to its starting point? George Pólya proved in 1921 that on a line and on a flat grid the answer is yes, with certainty, if you wait long enough. In three dimensions it is no: a walker on a cubic grid comes back with a chance of only about 34%. Shizuo Kakutani put it as 'a drunk man will find his way home, but a drunk bird may get lost forever.' The return can take very long, though: on a flat grid about 64% of walkers are back within 500 steps and 70% within 2,000, and the rest may need millions. The Back at the start tile counts them.

From walks to Brownian motion

Make the steps smaller and faster, and the random walk becomes Brownian motion, the jittering of pollen grains in water that Robert Brown saw in 1827. In 1905 Albert Einstein explained it as the sum of countless molecular kicks and showed that the mean squared displacement grows linearly with time, ⟨r²⟩ = 4Dt in two dimensions, with D the diffusion constant. Jean Perrin measured it in 1908 and used it to count molecules, which settled the question of whether atoms exist. The straight line of the app's Mean squared distance chart is the same law.

Where random walks turn up

Diffusion of heat, ink and perfume; the path of a photon that takes thousands of years to escape the Sun; the foraging of animals; the gambler's fortune in a fair game, where the gambler's ruin is a walk that hits zero; share prices, which Louis Bachelier modelled as a random walk in 1900; polymer chains; Google's original PageRank, a walk over the links of the web; and algorithms that explore a space too big to search, such as Monte Carlo methods. In each case the same √N rule says how fast the randomness spreads.

Explore it

Open the random walk, keep 1,000 walkers and 500 steps and press Play: the cloud of walkers spreads while the dashed circle of radius √N grows with it. Switch the chart to Mean squared distance to see the straight line, try a walk on a line to get a bell curve, and compare the 8 neighbours, whose diagonal steps are √2 long, so ⟨r²⟩ grows 1.5 times as fast. The tiles compare every simulated number with its theoretical value, and New run sends a fresh crowd of walkers off.

Frequently asked questions

How far does a random walker get after N steps?

Typically about √N steps from the start: the mean squared distance is exactly N for unit steps, so the root mean square distance is √N. The mean distance is a little less, about 0.886√N on a flat grid.

Why is the expected position zero if walkers move away?

Because a step in one direction is as likely as a step in the opposite one, the positions of many walkers average out at the start. Each walker still drifts away; they just drift in all directions equally.

Does a random walker always come back?

On a line and on a flat grid, yes, with probability 1 (Pólya, 1921), though it can take a very long time. On a three-dimensional grid it returns with a probability of only about 34%.

What is the link between random walks and diffusion?

Diffusion is a random walk of very many molecules with tiny steps. The mean squared displacement grows linearly with time, which is the random walk's ⟨r²⟩ = N in continuous form, as Einstein showed in 1905.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Open the random walk