Updated
In this lesson
Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.
Random walk
You will learn: Connect independent steps with displacement, drift, spread, and finite-time events.
Start with: Bernoulli distribution · Expectation and variance
A particle starts at position 0 and at each integer time step moves one unit right (with probability p) or one unit left (with probability 1 − p). Where does it end up after t steps?
Dashed outer curves show the expected position ±one pointwise standard deviation; the center line is the expectation. These are not hard path boundaries or a simultaneous confidence band. The dark accent path is walker one. All simulated positions fit the displayed vertical range.
Separate drift, spread, and distance traveled
| Quantity | Value |
|---|---|
| Expected signed position | 0.00000 |
| Position variance | 200.00000 |
| Position SD | 14.14214 |
| Mean simulated position | 0.70000 |
| Focus walk signed displacement | 10 |
| Focus walk distance from origin | 10 |
| Total distance traveled by each walker | 200 |
Write position as 2H−T with H binomial(T,p). Exact P(position=0) = 0.0563485; P(position≤0) = 0.528174. Possible positions have the same parity as T and lie in [−T,T]. The event always refers to original position, including when the display subtracts drift.
Inspect the focus walk step by step
| Step | Position |
|---|---|
| 0 | 0 |
| 1 | -1 |
| 2 | 0 |
| 3 | -1 |
| 4 | -2 |
| 5 | -3 |
| 6 | -2 |
| 7 | -3 |
| 8 | -4 |
| 9 | -3 |
| 10 | -4 |
| 11 | -3 |
| 12 | -2 |
| 13 | -1 |
| 14 | 0 |
| 15 | 1 |
| 16 | 2 |
| 17 | 3 |
| 18 | 4 |
| 19 | 5 |
| 20 | 4 |
| 21 | 5 |
| 22 | 6 |
| 23 | 7 |
| 24 | 8 |
| 25 | 7 |
| 26 | 6 |
| 27 | 7 |
| 28 | 8 |
| 29 | 7 |
| 30 | 6 |
| 31 | 5 |
| 32 | 6 |
| 33 | 5 |
| 34 | 6 |
| 35 | 5 |
| 36 | 4 |
| 37 | 5 |
| 38 | 4 |
| 39 | 5 |
| 40 | 6 |
| 41 | 7 |
| 42 | 8 |
| 43 | 9 |
| 44 | 8 |
| 45 | 7 |
| 46 | 8 |
| 47 | 9 |
| 48 | 10 |
| 49 | 9 |
| 50 | 8 |
| 51 | 9 |
| 52 | 8 |
| 53 | 7 |
| 54 | 8 |
| 55 | 9 |
| 56 | 8 |
| 57 | 7 |
| 58 | 6 |
| 59 | 5 |
| 60 | 4 |
| 61 | 3 |
| 62 | 2 |
| 63 | 3 |
| 64 | 4 |
| 65 | 3 |
| 66 | 4 |
| 67 | 3 |
| 68 | 2 |
| 69 | 1 |
| 70 | 0 |
| 71 | 1 |
| 72 | 0 |
| 73 | -1 |
| 74 | 0 |
| 75 | -1 |
| 76 | 0 |
| 77 | 1 |
| 78 | 2 |
| 79 | 3 |
| 80 | 4 |
| 81 | 3 |
| 82 | 2 |
| 83 | 1 |
| 84 | 2 |
| 85 | 1 |
| 86 | 0 |
| 87 | 1 |
| 88 | 2 |
| 89 | 3 |
| 90 | 2 |
| 91 | 3 |
| 92 | 4 |
| 93 | 3 |
| 94 | 2 |
| 95 | 3 |
| 96 | 4 |
| 97 | 5 |
| 98 | 6 |
| 99 | 7 |
| 100 | 6 |
| 101 | 5 |
| 102 | 6 |
| 103 | 5 |
| 104 | 4 |
| 105 | 5 |
| 106 | 4 |
| 107 | 5 |
| 108 | 4 |
| 109 | 3 |
| 110 | 2 |
| 111 | 3 |
| 112 | 4 |
| 113 | 5 |
| 114 | 4 |
| 115 | 5 |
| 116 | 4 |
| 117 | 3 |
| 118 | 4 |
| 119 | 5 |
| 120 | 4 |
| 121 | 3 |
| 122 | 2 |
| 123 | 3 |
| 124 | 4 |
| 125 | 5 |
| 126 | 6 |
| 127 | 5 |
| 128 | 6 |
| 129 | 5 |
| 130 | 6 |
| 131 | 5 |
| 132 | 4 |
| 133 | 3 |
| 134 | 2 |
| 135 | 3 |
| 136 | 4 |
| 137 | 5 |
| 138 | 6 |
| 139 | 7 |
| 140 | 6 |
| 141 | 5 |
| 142 | 6 |
| 143 | 7 |
| 144 | 8 |
| 145 | 9 |
| 146 | 8 |
| 147 | 9 |
| 148 | 10 |
| 149 | 11 |
| 150 | 10 |
| 151 | 11 |
| 152 | 10 |
| 153 | 9 |
| 154 | 10 |
| 155 | 9 |
| 156 | 10 |
| 157 | 11 |
| 158 | 10 |
| 159 | 9 |
| 160 | 8 |
| 161 | 9 |
| 162 | 10 |
| 163 | 9 |
| 164 | 8 |
| 165 | 9 |
| 166 | 10 |
| 167 | 11 |
| 168 | 10 |
| 169 | 9 |
| 170 | 10 |
| 171 | 11 |
| 172 | 10 |
| 173 | 11 |
| 174 | 10 |
| 175 | 9 |
| 176 | 8 |
| 177 | 7 |
| 178 | 8 |
| 179 | 9 |
| 180 | 8 |
| 181 | 9 |
| 182 | 8 |
| 183 | 9 |
| 184 | 8 |
| 185 | 9 |
| 186 | 8 |
| 187 | 7 |
| 188 | 8 |
| 189 | 9 |
| 190 | 10 |
| 191 | 9 |
| 192 | 10 |
| 193 | 9 |
| 194 | 10 |
| 195 | 9 |
| 196 | 10 |
| 197 | 11 |
| 198 | 10 |
| 199 | 9 |
| 200 | 10 |
Increasing T appends steps to each existing walker, and increasing walkers adds paths. The pointwise SD grows with √T for fixed p; one path need not stay near its expected position. Absorbing-boundary events require a hitting-time calculation rather than this endpoint distribution.
The √t law
For an unbiased walk (p = 0.5), the expected position is always 0 — steps cancel on average. But the spread grows:
For the fair case, the dashed curves show ±√t around zero. They are pointwise one-SD references, not barriers that a path must stay within. At 100 steps the SD is 10; at 10,000 steps it is 100. Spread grows as the square root of time, not linearly.
Bias
With p ≠ 0.5, each step has a net drift of 2p − 1 per step:
The amber center line shows expected position, with outer curves at ±√(4p(1−p)t) around it. A bias changes both the center and variance. At p=0.9 and t=100, the expected position is 80 and SD is 6. Plotting an unbiased ±√t envelope around zero would describe the wrong experiment.
For any fixed nonzero drift, its magnitude grows linearly in time while the centered SD grows as √t. This is an asymptotic comparison of scales, not a promise that every finite walk will follow the drift.
Diffusion and Brownian motion
The random walk is the discrete ancestor of Brownian motion. For the fair walk, under diffusive scaling that divides position by √n while accelerating time by n, the process converges to a continuous Gaussian process where position after time t is distributed as Normal(0, t). The same √t scaling survives in the limit — it is a fundamental feature of diffusion, not an artifact of the discrete model.
The Central Limit Theorem explains why: the position after t steps is a sum of t independent ±1 variables, and centering and scaling that finite-variance sum gives a normal limit. The exact finite-time position remains on a lattice.
Count right steps to find the endpoint law
Let H be the number of right steps. There are T−H left steps, so S_T=H−(T−H)=2H−T, with H binomial(T,p). At T=4 and p=1/2, the chance of ending at zero is the chance of two right steps: 6/16=0.375. The chance of ending at or below zero is (1+4+6)/16=0.6875.
Ending at position one after four steps is impossible: 2H−4 is even. The point-probability panel retains this parity constraint instead of filling every real-valued location with a normal approximation. The cutoff always concerns the original signed position, even in the centered display.
Displacement is different from distance traveled
The path right, right, left, left travels four units but ends where it started. Its signed displacement and distance from the origin are both zero. At a given time, averaging signed positions can also cancel positive and negative endpoints without saying that walkers traveled little.
Each step has mean 2p−1 and second moment one, hence variance 1−(2p−1)²=4p(1−p). Adding independent steps gives the drift and variance in the table. At p=0 or 1 there is no randomness: position is exactly −T or T and the variance is zero.
Make a prediction
Does knowing the endpoint probability tell you the probability that a walk hit a barrier earlier?
Explore the answer
No. A walk can cross a barrier and later return. A hitting event concerns the whole path, whereas the binomial calculation concerns only its endpoint. Use the gambler’s-ruin experiment for absorbing barriers.
References
Random Services: the simple random walk derives the endpoint distribution and increment moments. Continue to gambler’s ruin for hitting probabilities or binomial counts to inspect the right-step count.
Continue to martingales to distinguish conditional fairness from constant expectation and check bounded stopping rules.