b2KIT

Random Walk Simulator

Simulate 1D and 2D random walks with step visualization. Explore diffusion, return probability, and Brownian motion concepts.

Tested tool guide Tested browser tools Checked August 16, 2026

What Random Walk Simulator does, with a checked example

Flip a coin, move one step left or right, repeat a thousand times: that coin-toss record is a random walk, and this simulator draws it. Choose 1D or 2D, set the step count, and watch the path build point by point while the tool tallies the statistics: mean displacement, root-mean-square distance, and return visits to the origin. The surprise most people hit first: a walker whose steps average to zero does not hover near the start. Displacement stays near zero, but distance from the origin grows like the square root of the step count - 1,000 unit steps typically end about 32 units away.

Worked example

A concrete input and expected output from the current implementation.

Input

1D walk, 1,000 unit steps, repeated across 100 runs

Expected output

Mean final displacement: 0. Root-mean-square displacement: 31.6 (sqrt of 1,000). Typical distance from the origin: 25.2 (about 0.8 x sqrt of 1,000). The per-run endpoints scatter around the origin with a spread near 31.6.

Every step is +1 or -1 with equal probability, so the expected displacement is exactly 0 and the variance of the final position is exactly N = 1,000, making the RMS 31.6. The mean absolute displacement of a 1D symmetric walk is sqrt(2N/pi) = sqrt(2,000/pi), about 25.2, which the runs should track.

How the result is produced

1

Step generation

At each step the tool draws an independent move: in 1D, +1 or -1 with equal odds; in 2D, a unit step in a random direction. The position after t steps is the running sum of the moves, plotted point to point. Step count, dimension, and seed fix the path completely, so the same settings replay the same walk.

2

Ensemble statistics

A single path is one sample, so the tool aggregates many runs to estimate the distribution: mean displacement, root-mean-square displacement, and return visits to the origin. The benchmarks are exact: mean squared displacement after N unit steps is N, the position histogram converges to the normal curve (central limit theorem), and in 1D the probability of being back at the origin after 2n steps is C(2n,n)/4^n, about 1/sqrt(pi n).

Good uses

  • Verify the diffusion rule: run 100 steps, then 400, and check that the spread roughly doubles, because RMS displacement scales with sqrt(N). It is the same mechanism that makes diffusion spread like the square root of time.
  • Demonstrate Pólya's recurrence: watch 1D and 2D walks cross the origin repeatedly, the 'drunkard returns home' result that fails in three dimensions.
  • Build intuition for Brownian-motion price models: unpredictable unit steps still produce smooth-looking, self-similar trajectories whose volatility grows as sqrt(time), the core of geometric Brownian motion.

Limits and checks

  • A single run is a sample, not a prediction. The final position is one draw from a distribution; compare many runs and read the spread, not any one endpoint.
  • Mean displacement near zero does not mean the walker stays put: the expected distance from the origin is about 0.8 x sqrt(N), so a 1,000-step walk typically ends roughly 25 units away even though its mean position is 0.
  • Results assume unit steps: doubling the step length doubles displacements. Also, the path changes with every run unless you pin the random seed, so reproducibility requires fixing it.

Common questions

Why does the 1D walk keep returning to the origin even though it wanders far between visits?

For a symmetric walk in 1D and 2D, Pólya's theorem says the walker returns to the origin with probability 1 - indeed infinitely often. The visits get rarer as time passes: in 1D the chance of standing exactly on the origin after 10,000 steps is about 1/sqrt(pi x 5,000), roughly 0.8%. Long excursions between returns are the norm, not a bug.

Can I use this to predict where a stock price will go?

No. The simulator shows the random diffusion component that price models borrow, but it has no drift, no price jumps, no volatility clustering, and no autocorrelation between steps. Real returns are not independent coin flips. Use it to build intuition for Brownian-motion models, not to forecast a price.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools