← Math

🎲 Random Walk

Walkers: Step: Trail:
Walkers: 50

📊 Statistics

Steps: 0
Avg displacement: 0
√(steps) law: 0
Max distance: 0

🎲 Random Walk — Brownian Motion & Diffusion

At each step, a particle moves in a random direction. Over millions of steps the path looks like noise — yet it obeys precise mathematical laws: the average displacement grows as the square root of time, a signature of diffusion everywhere in nature.

🔬 What It Demonstrates

A 2D random walk is the discrete counterpart of Brownian motion (Einstein 1905). The mean-square displacement ⟨r²⟩ = 4Dt grows linearly with time, defining the diffusion coefficient D. In 1D/2D the walker always returns to the origin; in 3D it escapes with probability 1.

🎮 How to Use

Launch multiple walkers and watch their paths spread. Toggle between 2D grid and free 2D modes. The live histogram shows the radial distribution converging toward a Gaussian — the bell curve predicted by the diffusion equation.

💡 Did You Know?

Robert Brown observed pollen grains jiggling in water in 1827. Einstein's 1905 explanation — collisions with invisible molecules — provided the first indirect proof that atoms exist. Jean-Baptiste Perrin confirmed it experimentally, winning the 1926 Nobel Prize.

About this simulation

This sandbox launches a swarm of independent random walkers that each take a sequence of randomly directed steps on a 2D canvas. It contrasts three rules — a free continuous walk, a discrete lattice walk confined to four grid directions, and a heavy-tailed Lévy flight — and tracks the live statistics as the paths spread. The point is to watch order emerge from randomness: the average displacement grows in proportion to the square root of the number of steps, the universal signature of diffusion.

🔬 What it shows

Each walker updates its position every frame by adding a step. In free 2D mode the step has a fixed length at a uniformly random angle; the lattice mode picks one of four ±x/±y directions; the Lévy mode draws a step length from a power-law distribution P(x) ~ x^(-1.5) so rare long jumps dominate. The stats panel reports steps, average and maximum displacement, and the predicted √(steps) × step-size law, illustrating the diffusive scaling of Brownian motion.

🎮 How to use

Pick a mode with the 2D Walk, Lévy Flight or Lattice buttons. The Walkers slider sets how many particles run (1–200), Step controls the step length (1–10), and Trail sets how many past points each path retains (0–100). Reset restarts every walker from the centre. The canvas edges wrap around, so walkers reappear on the opposite side.

💡 Did you know?

A random walker on a 1D line or 2D plane is certain to return to its starting point eventually, but in three dimensions the return probability drops to about 34%. This result, proved by George Pólya in 1921, is often summed up as: "a drunk man will find his way home, but a drunk bird may not."

Frequently asked questions

What is a random walk?

A random walk is a path made of successive steps whose direction (and sometimes length) is chosen at random. Despite each step being unpredictable, the collection of paths follows precise statistical laws. It is the discrete mathematical model behind Brownian motion, the jittery motion of particles suspended in a fluid that Einstein explained in 1905.

What is the difference between the three modes?

The free 2D walk takes a fixed-length step in any continuous direction. The Lattice mode restricts each step to one of four grid directions (up, down, left, right), like a token on graph paper. The Lévy Flight draws step lengths from a heavy-tailed power-law distribution, so most steps are short but occasional very long jumps make the path spread far faster than ordinary diffusion.

What does the √(steps) law mean?

For ordinary diffusion the typical distance a walker travels from its start grows like the square root of the number of steps, not linearly with the steps themselves. The statistics panel shows the measured average displacement next to √(steps) multiplied by the step size, so you can see the simulated walkers track that theoretical prediction as they accumulate steps.

What do the sliders control?

The Walkers slider sets the number of simultaneous particles from 1 to 200, which makes the statistical averages smoother. The Step slider sets the length of each move from 1 to 10 pixels. The Trail slider sets how many previous positions are kept and drawn, from 0 (just the moving dot) up to 100 points of history per walker.

Why is the Lévy flight relevant to the real world?

Lévy flights, with their occasional long jumps, model many natural search and transport processes more accurately than plain diffusion. Foraging animals such as sharks and albatrosses, the spread of disease, and even fluctuations in financial markets show heavy-tailed step distributions, where rare large moves dominate the overall displacement.