---
title: Random walks and Brownian motion
heading: Why diffusion goes as the square root of time, from pollen grains to electrons crossing a transistor's base
eyebrow: B11 · Lesson 42 · Random walks
xp: 40
---

::: hook
In 1827 Robert Brown watched particles from pollen grains jitter endlessly in water. In 1905 Einstein explained the jitter as the particles being knocked about by molecules, and predicted how far they should wander; Jean Perrin's measurements of it fixed Avogadro's number and settled that atoms are real. The same mathematics, a random walk, describes an electron crossing a transistor's base, a dopant spreading in a furnace and heat soaking into a chip. Its central fact is that the distance covered grows as the square root of the time.
:::

::: play
- Each sample is one walker's position after N steps, each step a random length between −1 and +1. The histogram collects 5000 walkers.
- The curve is the Gaussian the central limit theorem predicts, with spread $\sqrt{N/3}$.
- Multiply N by 4 and the spread only doubles. That square-root growth is the signature of diffusion.
:::

```sim plot
view: random
x: x = -60..60
slider: N = 10..1000 step 10 = 100
sample: 2*rand(N) - N | sd: S
trials: 5000
bins: 60
density: exp(-x^2/(2*N/3))/sqrt(2*pi*N/3)
readout: spread of the walkers = S
readout: predicted √(N/3) = sqrt(N/3)
```

::: predict
## A drop of dye spreads 1 mm in water in about 10 minutes. About how long does it take to spread 1 cm?

- [ ] 100 minutes
- [x] About 1000 minutes, roughly 17 hours
- [ ] About 32 minutes
- [ ] 10 minutes, the same

::: reveal
About 1000 minutes. Diffusion distance grows as $\sqrt{Dt}$, so time grows as distance squared: ten times farther takes a hundred times longer. That's why diffusion moves things quickly across a cell or a transistor but uselessly slowly across a room, where currents of air do the mixing.
:::
:::

::: nameit
## The random walk

A walker takes N independent steps, each with mean zero and mean square $\ell^2$. The mean square displacements add, so

$$\langle x^2\rangle = N\ell^2, \qquad x_{rms} = \ell\sqrt N,$$

and by the central limit theorem the final position is Gaussian, as lesson 1's spin excess was. If a step happens every τ, then $N = t/\tau$ and $\langle x^2\rangle = 2Dt$ in each direction, with diffusion constant $D = \frac{\ell^2}{2\tau}$. In three dimensions $\langle r^2\rangle = 6Dt$.

## The diffusion equation

Many walkers released at one point spread into a Gaussian of width $\sqrt{2Dt}$, which is the solution of $\frac{\partial n}{\partial t} = D\frac{\partial^2n}{\partial x^2}$. Lesson 43 uses it for dopants and minority carriers, and heat flow obeys the same equation with thermal diffusivity in place of D.

## Brownian motion

A sphere of radius a moving through a liquid of viscosity η feels drag $6\pi\eta av$. Einstein showed that the same molecules that cause the drag cause the random kicks, and that

$$D = \frac{kT}{6\pi\eta a}.$$

More generally $D = \mu_mkT$, where $\mu_m$ is the velocity per unit force. For a charged carrier, with mobility μ as velocity per unit field, this is the Einstein relation $D = \mu\frac{kT}{q}$. Lesson 46 shows it's one case of the fluctuation–dissipation theorem.

## Carriers as walkers

An electron in silicon moves at its thermal speed and scatters every $\tau_m = \frac{\mu m^*}{q}$, a fraction of a picosecond, so its path is a random walk of tens of nanometers per step. Crossing a region of width W takes about $\frac{W^2}{2D}$, which sets a bipolar transistor's base transit time and with it the transistor's speed.
:::

::: example
## A bead 1 µm across sits in water at 20 °C (η = 1.0 mPa·s). What's its diffusion constant, and how far does it wander along one axis in 1 s and in 1 minute?

::: solution
1. **Diffusion constant.**
   $$\begin{aligned} D &= \frac{kT}{6\pi\eta a} \\ &= \frac{4.05 \times 10^{-21}}{6\pi \times 10^{-3} \times 0.5 \times 10^{-6}} \\ &= 4.29 \times 10^{-13}\ \text{m}^2/\text{s} \end{aligned}$$
2. **Wander along one axis.**
   $$x_{rms} = \sqrt{2Dt}$$
   gives 0.93 µm in 1 s and 7.2 µm in 60 s: sixty times the time, under eight times the distance.
3. **Perrin's measurement.** Perrin measured displacements like these under a microscope, and since $D$ contains Boltzmann's constant, $k = R/N_A$ gave him Avogadro's number.

**Answer:** D = 4.29 × 10⁻¹³ m²/s, and the bead wanders 0.93 µm in 1 s and 7.2 µm in a minute.
:::
:::

::: example
## Electrons in silicon have μ = 1350 cm²/(V·s) and conductivity mass 0.26$m_e$. What's their mean free time, and how long do they take to diffuse across a 1 µm transistor base at 300 K?

::: solution
1. **Mean free time.**
   $$\begin{aligned} \tau_m &= \frac{\mu m^*}{q} \\ &= \frac{0.135 \times 0.26 \times 9.11 \times 10^{-31}}{1.602 \times 10^{-19}} \\ &= 0.20\ \text{ps} \end{aligned}$$
2. **Step length.** At a thermal speed $\sqrt{3kT/m^*} = 2.3 \times 10^5$ m/s that's a step of about 46 nm.
3. **Diffusion constant.**
   $$\begin{aligned} D &= \mu\frac{kT}{q} \\ &= 34.9\ \text{cm}^2/\text{s} \end{aligned}$$
4. **Time to cross the base.**
   $$\begin{aligned} t &= \frac{W^2}{2D} \\ &= \frac{10^{-8}\ \text{cm}^2}{69.8\ \text{cm}^2/\text{s}} \\ &= 143\ \text{ps} \end{aligned}$$
5. **Thinner bases.** Halving the base width cuts this fourfold, one reason fast bipolar transistors have bases only tens of nanometers thick.

**Answer:** the mean free time is 0.20 ps, and crossing the 1 µm base takes 143 ps.
:::
:::

::: example
## A photon made in the Sun's core scatters off charged particles over and over. If its mean free path were 1 mm everywhere, how long would it take to random-walk out through the Sun's radius of $6.96 \times 10^8$ m?

::: solution
1. **Number of steps.** To get a distance R in three dimensions takes about
   $$\begin{aligned} N &= (R/\ell)^2 \\ &= (6.96 \times 10^{11})^2 \\ &= 4.8 \times 10^{23} \end{aligned}$$
   steps.
2. **Time.** Each step takes $\ell/c$, so
   $$\begin{aligned} t &= \frac{N\ell}{c} \\ &= \frac{4.8 \times 10^{23} \times 10^{-3}}{3 \times 10^8} \\ &= 1.6 \times 10^{12}\ \text{s} \\ &\approx 51\,000\ \text{years} \end{aligned}$$
3. **Compare with a straight flight.** A straight flight would take 2.3 s.
4. **The real Sun.** The true mean free path varies enormously with depth, and careful estimates range over tens of thousands to a couple of hundred thousand years, but the square-root law is why the answer is in millennia at all.

**Answer:** about $1.6 \times 10^{12}$ s, or 51 000 years.
:::
:::

::: check
kind: parts
given: a = 0.1 | 0.5 | 2; T = 293 | 310; v = 0.7 | 1

## A sphere of radius {a} µm sits in a liquid of viscosity {v} mPa·s at {T} K.

::: part
answer: 1.380649e-23*T/(6*pi*v*1e-3*a*1e-6)*1e12
unit: µm²/s
tolerance: 0.5%

### What's its diffusion constant?

::: misses
- [1.380649e-23*T/(6*pi*v*1e-3*2*a*1e-6)*1e12] Use the radius, not the diameter.
- [any] Stokes–Einstein: $D = \frac{kT}{6\pi\eta a}$.
:::
:::

::: part
answer: 100/(6*1.380649e-23*T/(6*pi*v*1e-3*a*1e-6)*1e12)
unit: s
tolerance: 0.5%

### How long until its three-dimensional RMS displacement reaches 10 µm?

::: misses
- [100/(2*1.380649e-23*T/(6*pi*v*1e-3*a*1e-6)*1e12)] In three dimensions $\langle r^2\rangle = 6Dt$.
- [any] $t = \frac{r^2}{6D}$.
:::
:::
:::

::: check
given: N = 100 | 10000 | 1000000; l = 0.5 | 2
answer: l*sqrt(N)
unit: nm
tolerance: 0.5%

## A walker takes {N} random steps of {l} nm each, in random directions. What's its RMS distance from the start?

::: right
Right. $\ell\sqrt N$.
:::

::: misses
- [l*N] Steps in random directions mostly cancel; only the mean squares add.
- [any] $\langle r^2\rangle = N\ell^2$.
:::
:::

::: check
given: W = 0.1 | 1 | 10; D = 10 | 35
answer: (W*1e-4)^2/(2*D)*1e12
unit: ps
tolerance: 0.5%

## Minority carriers with D = {D} cm²/s diffuse across a {W} µm base. About how long does it take?

::: right
Right. $\frac{W^2}{2D}$.
:::

::: misses
- [(W*1e-4)^2/D*1e12] The base transit time is $\frac{W^2}{2D}$.
- [any] Convert µm to cm, then $\frac{W^2}{2D}$.
:::
:::

::: check
given: u = 450 | 1350 | 8500; m = 0.067 | 0.26 | 0.39
answer: u*1e-4*m*9.1093837e-31/1.602176634e-19*1e12
unit: ps
tolerance: 0.5%

## A carrier has mobility {u} cm²/(V·s) and effective mass {m}$m_e$. What's its mean free time?

::: right
Right. $\tau_m = \frac{\mu m^*}{q}$.
:::

::: misses
- [u*m*9.1093837e-31/1.602176634e-19*1e12] Convert cm²/(V·s) to m²/(V·s).
- [any] $\tau_m = \frac{\mu m^*}{q}$.
:::
:::

::: check
kind: choice

## Why does a random walker's distance from the start grow as $\sqrt t$ rather than as t?

- [ ] It slows down as it tires
- [ ] Friction removes its energy
- [x] Its steps point in random directions, so their sum grows only as the square root of their number
- [ ] Each step is shorter than the last

::: right
Right. Independent steps add in quadrature: N steps of size ℓ reach $\ell\sqrt N$ on average.
:::

::: misses
- [1] Its speed doesn't change; the directions are what's random.
- [2] A Brownian particle is in thermal equilibrium; it keeps its kT of kinetic energy.
- [4] The steps are all the same size on average.
:::
:::

::: check
given: D = 1 | 35; t = 1 | 100
answer: sqrt(6*D*t*1e-9)*1e4
unit: µm
tolerance: 0.5%

## A particle diffuses with D = {D} cm²/s. What's its three-dimensional RMS displacement after {t} ns?

::: right
Right. $\sqrt{6Dt}$.
:::

::: misses
- [sqrt(2*D*t*1e-9)*1e4] That's along one axis; in three dimensions it's $\sqrt{6Dt}$.
- [any] $\langle r^2\rangle = 6Dt$.
:::
:::

::: check
given: l = 1 | 10 | 50; t = 0.1 | 1 | 100
answer: (l*1e-7)^2/(2*t*1e-12)
unit: cm²/s
tolerance: 0.5%

## A walker takes a {l} nm step along one axis every {t} ps, in either direction. What's its diffusion constant?

::: right
Right. $D = \frac{\ell^2}{2\tau}$.
:::

::: misses
- [(l*1e-7)^2/(t*1e-12)] With $\langle x^2\rangle = 2Dt$, the step gives $D = \frac{\ell^2}{2\tau}$.
- [any] $D = \frac{\ell^2}{2\tau}$.
:::
:::

::: check
kind: derivation
vars: N = 1..1000000, l = 0.1..10

## A walker takes N independent steps along a line, each of mean zero and RMS size l.

::: step
answer: N*l^2

### What's its mean square displacement?
:::

::: step
answer: l*sqrt(N)

### What's its RMS displacement?
:::

::: step
answer: 1/sqrt(2*pi*N*l^2)

### For large N, what's the probability density of ending exactly back at the start?
:::

::: right
Right. The chance of being near the start falls as $1/\sqrt N$ as the distribution spreads.
:::
:::

::: check
kind: python

## Write `walk(N, M, seed)` returning a NumPy array of the final positions of M walkers that each take N steps of ±1, and `fraction_beyond(x, limit)` returning the fraction of positions with $|x| >$ `limit`. Use `np.random.default_rng(seed)`.

```python starter
import numpy as np

def walk(N, M, seed):
    return np.zeros(M)

def fraction_beyond(x, limit):
    return 0.0

x = walk(400, 20000, 1)
print(np.mean(x**2), fraction_beyond(x, 40))
```

```python solution
import numpy as np

def walk(N, M, seed):
    rng = np.random.default_rng(seed)
    heads = rng.binomial(N, 0.5, size=M)
    return 2 * heads - N

def fraction_beyond(x, limit):
    return float(np.mean(np.abs(x) > limit))

x = walk(400, 20000, 1)
print(np.mean(x**2), fraction_beyond(x, 40))
```

```python tests
import numpy as np
x = walk(400, 20000, 1)
assert len(x) == 20000, "Return one position per walker."
assert np.all(x % 2 == 0), "After an even number of ±1 steps the position is even."
assert abs(np.mean(x**2) / 400 - 1) < 0.04, f"The mean square should be about N = 400; got {np.mean(x**2)}"
f = fraction_beyond(x, 40)
assert 0.035 < f < 0.06, f"About 4.6% of walkers end beyond 2√N = 40; got {f}"
```

::: right
Right. The mean square equals N, and about 4.6% of walkers land beyond two standard deviations, as the Gaussian predicts.
:::
:::

::: explain
## Why do the same molecular collisions that slow a Brownian particle also make it wander?

::: model
Each molecule that hits the particle transfers a little momentum. On average, a moving particle is hit harder from the front than from behind, which is the viscous drag. But the hits are random, so at any moment they don't balance exactly, and the leftover pushes the particle in random directions. Both effects come from the same collisions, so they're linked: the stronger the drag (a larger particle or a thicker liquid), the more the kicks are averaged away and the smaller the diffusion constant, $D = \frac{kT}{6\pi\eta a}$. The temperature sets how hard the kicks are. A particle in equilibrium keeps its ½kT per direction of kinetic energy, and the drag constantly removes the energy the kicks add.
:::
:::

::: practice

::: check
given: N = 400 | 40000; l = 1 | 3
answer: l*sqrt(N)
unit: nm
tolerance: 0.5%

## RMS distance after {N} random steps of {l} nm?

::: misses
- [any] $\ell\sqrt N$.
:::
:::

::: check
given: W = 0.05 | 0.5; D = 12 | 30
answer: (W*1e-4)^2/(2*D)*1e12
unit: ps
tolerance: 0.5%

## Diffusion time across {W} µm with D = {D} cm²/s?

::: misses
- [any] $\frac{W^2}{2D}$.
:::
:::
:::
