Home / Science / Physics / Thermodynamics and statistical physics / Random walk and diffusion simulatorTool #922

Random walk and diffusion simulator: mean square displacement and diffusion coefficient from simulations or particle tracks

Simulate lattice or Gaussian random walks in 1, 2 or 3 dimensions and watch the mean square displacement grow as 2dDt, or paste your own particle tracks to fit the diffusion coefficient, localisation error and anomalous exponent from the time-averaged MSD.

Keep it one tap away for everyday use.

Bookmark Random walk and diffusion simulator?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. Walk
  2. MSD
  3. Tracks
  4. Fit D
Nothing is uploadedWorks offline once open

Simulate a random walk

Each walker starts at the origin and takes independent random steps. Theory says the mean square displacement grows as 2·d·D·t with D = a² / (2·d·Δt). The same seed repeats a run exactly.

Fit D from your tracks

Frames should be evenly spaced in time; missing frames are fine. Short lags carry the most information: fit the first few (often a quarter of the track length or less). The offset absorbs position noise, which adds 2·d·σ² to every MSD value.

Download

What it does

A particle jostled by random kicks wanders off in a random walk. It goes nowhere on average, but its mean square displacement (MSD) grows steadily with time: MSD = 2·d·D·t in d dimensions, where D is the diffusion coefficient. That straight line is how D is measured, from molecules in a cell to pollen grains in water.

The tool has two parts:

  • Simulate: hundreds of walkers on a line, a plane or in space, with steps of fixed length along the axes (lattice) or random Gaussian steps. You see the first ten paths, the MSD against time next to the theory line 2·d·D·t with D = a²/(2·d·Δt), the fitted D and exponent α, and a histogram of where the walkers ended up compared with the Gaussian the diffusion equation predicts.
  • Fit your tracks: paste or open particle tracks (track name, time, x, y and optionally z). The tool works out the time-averaged MSD over all tracks at each lag, fits D over the first lags (with an optional offset for localisation error) and the anomalous exponent α from the log-log slope.

How to use it

  1. For a simulation, choose the dimensions, step type, number of walkers, steps, step length and time per step. Change the seed for a different random run.
  2. For tracks, paste rows like T1, 0.10, 2.315, 4.017 (or press Use the example tracks, or Open a file). Choose x only, x-y or x-y-z, and whether the first column is a track name. Set the units for the labels.
  3. Choose how many lags to fit (the first few are most reliable) and whether to fit an offset.
  4. Download the MSD tables as CSV, or the report as an image, PDF or Word file.

Worked example

The default simulation: 500 walkers on a 2D lattice, 1000 steps of length 1 each taking 1 time unit (seed 1). Theory gives D = 1²/(2·2·1) = 0.25; the fit gives 0.2438, and the MSD after 1000 steps is 951.9 against the expected 1000. The exponent α is 0.9788, close to 1. With 500 walkers the run-to-run scatter is a few per cent; more walkers bring the fit closer.

The example tracks are 10 made-up tracks of 100 frames, 0.1 s apart, simulated with D = 0.5 µm²/s and 0.03 µm of position noise. Fitting the first 10 lags with an offset gives D = 0.4658 µm²/s, an offset of 0.0163 µm² (position noise of about 0.0638 µm) and α = 0.9695. The estimate is a few per cent below the true 0.5 because ten short tracks only sample a little of the random motion.

Tips

  • The fit error assumes independent points; MSD values at neighbouring lags are strongly correlated, so treat it as a lower bound.
  • α well below 1 suggests confinement or crowding; α above 1 suggests flow, drift or active transport.
  • A negative offset usually means motion blur during the camera exposure.

FAQ

Why only the first lags? Long lags are averaged over few pairs and are noisy.

Does the tool upload my tracks? No: everything is computed in your browser. For study and planning, not a substitute for a full tracking analysis.

Where the numbers come from

  • Random walks, the diffusion equation and MSD = 2dDt: Einstein, A. (1905), Annalen der Physik 17, 549; standard treatment in Berg, H. C., Random Walks in Biology.
  • MSD analysis of single-particle tracks with a localisation offset and the anomalous exponent: standard practice, for example Michalet, X. (2010), Physical Review E 82, 041914.
  • Checked against an independent NumPy script (MSD by array differences, numpy.linalg.lstsq and polyfit fits) and simulations against D = a²/(2 d Δt).
  • The example tracks are made up: simulated Brownian motion with D = 0.5 µm²/s, 0.1 s frames and 0.03 µm noise.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Trend and anomaly analyser #138 Paste or open a time series (yearly, monthly or any steps) and test for a trend with Mann-Kendall, the Hamed-Rao autocorrelation correction or the seasonal test, get Sen's slope with its confidence interval, a Pettitt change point and anomalies from a baseline period. Ising model playground #918 Watch a 2D Ising magnet order and disorder as you move the temperature, then scan a range of temperatures for magnetisation, energy, heat capacity, susceptibility and the Binder cumulant with error bars, compared with Onsager's exact result. Partition function explorer #919 Type or paste energy levels with their degeneracies, or make oscillator, rigid-rotor or two-level ladders, and get the partition function, Boltzmann populations, mean energy, entropy, Helmholtz energy and heat capacity at any temperature, with charts against temperature. Publication plot maker #27 Paste columns or open a CSV or Excel file and get a clean scientific figure with error bars, sized for a journal column. Download vector SVG or PDF, or PNG at 300 or 600 dpi. Your data stays in your browser. Real gas calculator #916 Compare the ideal gas law with four cubic equations of state for any gas: compressibility factor Z, molar volume, density and fugacity side by side, the saturation pressure each equation predicts, and charts of Z against pressure, the P-V isotherm and a generalised Z chart. Heat engine cycles #917 Draw the air-standard Carnot, Otto, Diesel, Brayton and Stirling cycles on pressure-volume and temperature-entropy diagrams, with every state, the heat and work of each process, net work, mean effective pressure and efficiency against the Carnot limit.