Random Walks, Explained
After reading this you will know why a plain random walk drifts outward like \sqrt{n}, why a Lévy flight covers ground far faster, and why a self-avoiding walk swells and then chokes itself. You will be able to predict typical distances from step counts and check them against the live plot.
What a random walk is
A random walk is a path built one random step at a time. Start a walker at the origin. At each tick it picks a direction (and sometimes a length) at random and moves. Repeat. The rule is trivial. The behaviour is not.
Here is the hook. Put 500 walkers at the origin and let each take a plain step north, south, east or west, chosen uniformly, for 400 steps. They do not stay put and they do not fly off in a line. They form an expanding blurry disk. The typical walker sits about \sqrt{400} = 20 steps from the center, not 400 and not 0. That square-root law is the fingerprint of ordinary diffusion, and it shows up in ink spreading through water, in stock prices, and in the jitter of pollen grains that Einstein explained in 1905.
The tool runs three flavours side by side: a plain 2D walk, a Lévy flight with rare long jumps, and a self-avoiding walk that refuses to cross its own trail. Each spreads at a different rate, and the live distance plot makes the difference obvious.
When the model fits and when it does not
Reach for a random walk when the thing you study takes many small independent nudges with no memory of the past. Diffusion of heat or gas, the price of a liquid asset over short intervals, the position of a foraging animal, the shape of a floppy polymer in solvent: all are modelled well by one of these three variants.
Do not use it when steps are strongly correlated or when the system has a restoring force. A pendulum returns to center, so it is not a free walk. A trending market with momentum violates the independence assumption. A molecule bound in a crystal lattice vibrates but does not wander. If your data shows distance growing linearly with time rather than as a square root, a diffusive walk is the wrong model.
A single walker is nearly useless for measuring a growth law. One path is one noisy sample. To see \sqrt{n} emerge you must average the squared distance over many walkers. Ten is rough, a few hundred is convincing.
The formula and the intuition
Write the walker's position after n steps as the sum of the individual step vectors. For a plain walk each step has length 1 and a random direction, so its expected displacement is zero: the walker is equally likely to go left or right. The mean position stays at the origin forever. The useful quantity is the mean squared displacement.
Here \vec{s}_i is the i-th step vector, r_n is the distance from the origin after n steps, and the angle brackets mean an average over many walks. Because steps are independent and their directions average out, every cross term \langle \vec{s}_i \cdot \vec{s}_j \rangle with i \ne j is zero. Each step has length 1, so \langle |\vec{s}_i|^2 \rangle = 1. The sum collapses to a clean result.
Double the steps and the typical distance grows only by \sqrt{2} \approx 1.414. That is diffusion. More generally the growth follows a power law r \approx n^{\nu} with an exponent \nu that names the regime.
- Plain walk
- \nu = 0.5. Distance scales as \sqrt{n}. Slow, diffusive.
- Self-avoiding walk (2D)
- \nu = 3/4 = 0.75 (Flory's result). Swells faster because it cannot fold back onto itself.
- Lévy flight
- Step lengths drawn from a heavy tail P(\ell) \propto \ell^{-1-\alpha} with 0 \lt \alpha \lt 2. Variance diverges, so the square-root argument breaks and the walk spreads super-diffusively.
A worked example with the demo data
Press the demo button and it runs the field defaults: a plain 2D walk with n = 400 steps averaged over a batch of walkers. Follow the numbers for a single walker before trusting the batch.
Tracking one plain walker for four steps
Steps go north, south, east or west with equal probability. Suppose the random draws are E, N, E, S.
- Start at
(0, 0). - E: move to
(1, 0). Distance1. - N: move to
(1, 1). Distance \sqrt{2} \approx 1.414. - E: move to
(2, 1). Distance \sqrt{5} \approx 2.236. - S: move to
(2, 0). Distance2. Squared distance4.
One walker landed at squared distance 4 after 4 steps. That matches the prediction \langle r_4^2 \rangle = 4, but only by luck. The next walker might return to the origin (squared distance 0) or reach r^2 = 16. The theory speaks about the average, not any single run.
Now scale up to the demo's 400 steps. The predicted mean squared displacement is 400, so the typical distance is \sqrt{400} = 20. Averaging squared distance over a batch of 500 walkers should land within a few percent of 400. The chart below shows the theoretical curve you are checking against.
Reading the distance plot
The live plot shows typical distance against step count for each walk type. Three habits help you read it.
First, expect noise. Even with 500 walkers the plain-walk curve wobbles a few percent around \sqrt{n}. That is sampling error, not a flaw in the theory. Quadrupling the walker count roughly halves the wobble, because standard error falls as 1/\sqrt{N}.
Second, judge the exponent by shape, not by height. A curve that keeps its slope constant on log-log axes is a clean power law. On linear axes the plain walk bends over (concave), the self-avoiding walk bends less, and a Lévy flight climbs steeply with jagged jumps from single long steps.
Third, watch the self-avoiding walk stall. Because it cannot revisit a cell, a walker sometimes surrounds itself and runs out of legal moves. When that happens the path ends early. In dense 2D lattices this trapping is common past a few hundred steps, which is why long self-avoiding walks are hard to sample.
| Walk type | Exponent \nu | Formula | Distance at n=400 |
|---|---|---|---|
| Plain 2D | 0.5 | \sqrt{n} | 20 |
| Self-avoiding | 0.75 | n^{3/4} | 89.44 |
| Lévy (typical) | > 0.75 | heavy-tailed | varies, often 150+ |
Common mistakes
Averaging distance instead of squared distance. The clean law is \langle r^2 \rangle = n. The mean of r itself is smaller than \sqrt{\langle r^2 \rangle} because of Jensen's inequality. For a 2D walk the mean distance is about 0.886\sqrt{n}, so at n = 400 you get roughly 17.7, not 20. Decide which statistic you want and stay consistent.
Trusting one Lévy run. A Lévy flight's distance is dominated by its single longest jump. One walker might travel 300 units, the next 40. You need a large batch, and even then the average is unstable because the underlying variance is infinite for \alpha \lt 2.
Reading trapping as slow spreading. When self-avoiding walks stop early, the surviving long walks are biased toward open, stretched-out shapes. Averaging over only the survivors inflates the apparent exponent. This is a real sampling trap, not a property of the model.
To estimate an exponent yourself, record \langle r^2 \rangle at several step counts, take logs, and fit a line. The slope on a log-log plot of r against n gives \nu directly. A slope near 0.5 confirms ordinary diffusion.
Related tools
Random walks sit inside a wider family of simple rules that generate rich structure. For growth on a grid governed by neighbour counts, see Conway's Game of Life and the one-dimensional Elementary Cellular Automata. For deterministic chaos that still looks random, trace the Lorenz Attractor or sweep the Logistic Map Bifurcation. The Chaos Game shows how random choices can build an exact fractal, and Flow-Field Particles replaces pure randomness with a smooth noise field to steer many walkers at once. For pure fractal geometry, zoom into the Mandelbrot Explorer.
Frequently asked questions
Why does the walker end up so close to where it started?
Because steps in opposite directions cancel on average. After 400 steps the expected position is still the origin, and the typical distance is only \sqrt{400} = 20, which is 5 percent of the total path length of 400. Wandering is inefficient at covering distance.
What makes a Lévy flight spread faster than a plain walk?
Its step lengths come from a heavy-tailed distribution, so rare enormous jumps happen often enough to matter. The variance of a single step is infinite, so the \sqrt{n} argument fails and the walk explores new ground far more quickly. Sharks, bees and hungry humans searching for scattered food show this pattern.
Will a plain 2D walk always return to the origin?
In one and two dimensions, yes, with probability 1 given infinite time (Polya's theorem). In three dimensions it returns only about 34 percent of the time. Two dimensions is the boundary case: recurrent but painfully slow, since the expected return time is infinite.
Why do self-avoiding walks sometimes just stop?
The walker can wall itself in. If all neighbouring cells are already visited, no legal move remains and the path terminates. On a square lattice this happens increasingly often past a few hundred steps, which is why sampling very long self-avoiding walks needs special algorithms.
How many walkers do I need for a reliable distance curve?
The scatter in the estimated mean falls as 1/\sqrt{N}. With 100 walkers expect about 10 percent noise, with 400 about 5 percent, with 2500 about 2 percent. For a smooth plain-walk curve a few hundred is enough; Lévy flights need thousands because of their fat tail.