Random Walks
Random Walks
A random walk is one of the most fundamental stochastic processes in science, underpinning Brownian motion, diffusion, polymer conformations, financial models, and search algorithms.
1D Random Walk
In the simplest version, a walker on the integer number line takes steps of or with equal probability. After steps the walker is at position where each .
Key results:
- Mean displacement: (symmetric walk)
- Mean squared displacement (MSD):
- Root-mean-square displacement:
The MSD grows linearly with time — this is the signature of diffusion. In general, for diffusion coefficient :
(in 1D, where counts discrete steps and for unit steps of size 1).
Reproducibility: Linear Congruential Generator
For deterministic, reproducible walks we use a Linear Congruential Generator (LCG):
with parameters , , .
A uniform value in is obtained as . If the walker steps , otherwise .
Mean First Passage Time
For a 1D symmetric random walk starting at the origin, the expected number of steps to first reach position (the mean first passage time) is:
This quadratic scaling has practical consequences: diffusion is a slow search strategy for large distances.
Your Task
Implement four functions:
lcg_step(state)— one LCG step, returning(value, new_state)wherevalueis inrandom_walk_1d(N, seed=42)— simulate a 1D random walk of steps using the LCG, return final positionrandom_walk_variance(N)— return the theoretical variancemsd_theoretical(N, D=1)— return the theoretical MSD for 1D diffusion