Back

Thinking About Random Walks

Random walks are fundamental models in probability theory with wide-ranging applications. This study investigates the statistical behavior of discrete, unbiased random walks in one, two, three, and higher dimensions through large-scale Python simulations involving up to 50,000 trials and 10,000 steps per walk. We empirically estimate the probability that a random walker returns to the origin within a finite number of steps and the expected distance a d-dimensional walker traverses, finding strong agreement with theoretical predictions: for both, we compute additional experimental values in higher-dimensional walks. We continue to show that histograms of Euclidean distance and displacement asymptotically converge to a Gaussian, though at different rates. Future studies may extend this framework for biased or constrained walks, providing a basis for more specific physical and biological models of transport and movement.

Originally introduced by Karl Pearson in 1905 to describe the path of a drunken man, the mathematical and statistical treatment of random walks has since matured into a core area of stochastic process theory, with numerous applications from molecular diffusion and polymer dynamics to ecological modeling and financial systems [1]. Mathematically, we consider a simple symmetric random walk (SSRW) in d-dimensional space as beginning at the origin and moving exactly one unit at each discrete time step along 2d possible coordinate directions. Formally, the position of the walker after n steps is given by the sum of independent, identically distributed step vectors:

Xn= ∑i=1n Si where Si∈ {±e1,±e2,…,±ed}

{ej} is the standard basis for ℝd. Each step Si is sampled uniformly from this set. A central question in the study of random walks concerns the probability that the walker ever returns to the origin. Let P(d) be the probability that a random walk on d dimensions returns to the origin. The walk is said to be recurrent if the walker returns to the origin with a probability of 1, and transient otherwise. It has been proven [2] that the SSRW is transient for d≥3. That is, P(d)<1 for d>2. This is done [3] by determining convergence of the improper integral:

∫N∞ t−d/2 dt forN≫0

Another important result [4] shows that, for d=3 specifically:

P(3)=1− 1 3(2π)3 ∫−ππ ∫−ππ ∫−ππ dxdydz 3−cos⁡x−cos⁡y−cos⁡z =0.3405…

Two other classical questions concern the expected displacement and distance of the walker after n steps. Intuitively, since the walk is symmetric, the expectation E(Xn) is zero. But, using the fact that E(Sn2)=1, it can be shown [5] that:

E(Xn2)= ∑i=1n E(Si2) +2 ∑1≤i≤j≤n E(SiSj) =n

This hints that E(|Xn|), the expected distance after n steps, is of the order n. Indeed, it has been shown [6] for d=1:

E(|Xn|)= 2nπ

While these results are well known in the asymptotic sense, less emphasis has been placed on empirical studies that explore the finite-time behavior of these processes in higher dimensions. Notably, the probability of return for d>3 does not exhibit a known closed form. This is also true of E(|Xn|) for d>2: Numerical estimation so far remains the only way to approximate these results. This study thus reformulates the mathematical ideas shown above through simulation to resolve these issues, and investigates how the behavior of discrete random walks changes as dimension count increases, using Python to generate high-resolution figures of return probability, displacement, and Euclidean distance along with their relevant histograms.

In this study, we aim to model the SSRW in Python as a testable simulation that may be iterated across multiple dimensions. From now onwards, each walk will be referred to as a “trial” and each movement as a “step”. As above, our walks begin at the origin, and the walker moves exactly one unit along one of the 2d possible directions per step, chosen uniformly at random. Each trial simulates a SSRW of a fixed number of steps, and many such trials are conducted to collect statistically significant estimates of return probability, final displacement, and expected distance. The latter of these will for our purposes be used interchangeably with Euclidean distance, as both represent the l2 norm. We use 50000 trials for each simulation, varying the number of steps to fit our needs.

We choose two sets of parameters: one to generate histograms of displacement and Euclidean distance and their estimated Probability Density Functions (PDFs), mean displacement and Euclidean distance, and return probability (Category 1); and the other for plots of the mean Euclidean distance as functions of the number of steps (Category 2), differing slightly.

Both categories use 50,000 trials (N) and dimensions (D) one through five. They differ only in the number of steps (S): Category 1 runs each trial for 10,000 steps, while Category 2 sweeps the step count from 1 to 100 so that distance can be plotted against it.

Spyder, a Python Integrated Development Environment running on version 3.12, was downloaded on Anaconda Navigator. To simulate the SSRW, a three dimensional array “walks” is created to store the position of each trial at each step. The evolution of the trial is then simulated step by step. The “move” array randomly selects one of the 2D possible directions for each trial from a range of 0 to 2D−1. This array has two purposes: “axis” dictates which axis the step occurs on by applying integer division on “move”, resulting in a mapping of 0 and 1 to axis 0, 1 and 2 to axis 2, and so on. “direction” dictates the direction of the step by applying modular arithmetic on “move”, checking if the direction selected by “move” is odd or even, assigning a step of +1 or -1 respectively along the relevant axis. A “step” array is created that holds this information for each trial. For each trial, +1 or -1 is placed in the appropriate axis column, leaving all axes at zero, creating a vector that describes the dimension and step direction. This computed vector is added to the current position to update the walker’s position. By the end of this loop, the full trajectory of each trial has been computed.

This simulation is highly generalizable. By changing the “dimension” parameter, trials in any integer dimension larger than 1 may be simulated. Moreover, because the simulation builds full trajectories of each trial, it supports further visual trajectory inspection, return statistics, and displacement metrics.

i. Visualizations were generated to illustrate sample random walk trajectories in one, two, and three dimensional walks.

ii. The probability that any trial returns to the origin is computed, mathematically corresponding to checking if: ∃n∈{1,2,…,N} such that Xn=0. The empirical return probability over N trials is computed as the fraction of trials that satisfy this condition: We iterate this value over different S to plot the empirical return probability as a function of the number of steps.

iii. The final displacement over a specific axis for each trial is computed by analyzing the individual coordinates of Xn at the final step and is used to generate the final displacement histograms. The mean final displacement over D dimensions is computed by averaging this quantity across N trials.

iv. The final Euclidean distance for each trial is computed, mathematically corresponding to finding the l2 norm:

‖Xn‖= XN,12+ XN,22+ …+ XN,D2

This quantity is used to generate the final Euclidean distance histogram. The mean final Euclidean distance over D dimensions is computed by averaging this quantity across N trials: We iterate this value for different S to plot the mean final Euclidean distance as a function of the number of steps.

v. Histograms are overlaid with fitted PDFs using estimated mean and variance from simulation data.

vi. Plots are generated of the mean Euclidean distance E(|Xn|) as functions of the number of steps S. Linearization is performed on the plot by squaring values of E(|Xn|), and linear regression is used to compute the empirical relationship between E(|Xn|) and S.

i. Asymptotically, the distribution of final Euclidean distances tends towards a Gaussian.

Sample trajectories of five walkers over 10,000 steps give a sense of the scale involved: in one dimension the walkers wander roughly 150 units above and below the origin, in two dimensions they fill a cloud about 150 units across, and in three dimensions they form tangled paths within a similar range. Histograms of the final Euclidean distance, each overlaid with a Gaussian fitted to the sample mean and variance, tell the main story. In one dimension the distances pile up near zero and tail off to the right, so the fitted curve misses badly on the left side. In two dimensions the pile-up softens and the fit improves. From three dimensions onward the histogram and the fitted curve nearly coincide, with the peak drifting toward about 100 units and the spread narrowing as the dimension rises.

We observe that as d increases, the Euclidean distance of a d-dimensional walk increasingly exhibits a close correlation to the Gaussian distribution for 1≤d≤5.

ii. The distribution of final displacements tends towards a Gaussian.

Displacement along each coordinate axis behaves differently. Its histograms are centered on zero and symmetric in every dimension, and the fitted Gaussian lies almost exactly on top of the data from one dimension onward. Overlaying the per-axis histograms for a given walk shows them matching one another closely. The spread shrinks as the dimension grows, from roughly plus or minus 400 units in one dimension to about plus or minus 200 in five, because each axis receives only a fraction of the total steps.

We observe that each axis of a d-dimensional walk exhibits close correlation to the Gaussian distribution for 1≤d≤5.

iii. Return probability decreases as d increases.

The empirical return probability within 10,000 steps drops steeply at first and then flattens as the dimension rises: nearly every walker returns in one dimension, about three quarters return in two, and the share falls to roughly one third in three dimensions before leveling off near one fifth and one eighth in four and five.

We observe that for D ranging from 1-5, the corresponding probability that walkers returned at least once to the origin were 0.9922, 0.7373, 0.3342, 0.1955, and 0.1318 respectively.

iv. Euclidean distance scales proportionally with the square root of S.

Measuring the mean Euclidean distance at step counts of 1, 5, 10, and so on up to 100 shows the same pattern in every dimension. The measured distances climb from 1 at a single step to between 7.94 (one dimension) and 9.52 (five dimensions) at 100 steps, with higher dimensions consistently a little farther from the origin at every step count. Plotting squared distance against step count produces a tight straight line through the origin in every dimension, with slopes of 0.6366, 0.7884, 0.8493, 0.8857, and 0.9066 for one through five dimensions.

We observe that for {S∈ℤ|0<S≤100∧Smod5=0}, squared Euclidean distance in one dimension approached 0.7979S. In two to five dimensions, these quantities were 0.8879x, 0.9216x, 0.9411x, and 0.9522x respectively.

This study empirically investigated key statistical properties of SSRWs in one to five dimensions, with a particular focus on return probability, displacement, and Euclidean distance. Through extensive Python simulations, we first validated classical theoretical results. Our computation for P(3) differed from the known theoretical value by less than 1.8502%. A similar comparison between the experimental and theoretical values of E(|Xn|) for d=1 yielded error less than 0.0019%. Given the low error of these values, we then extended these results into dimensions for which no closed-form solutions exist, providing accurate numerical results that may be further extrapolated in the future. This study also serves as a demonstration of the Central Limit Theorem, as we observe that key properties of random walks inherently tend towards Gaussian Distributions, which hold even at higher dimensions. These empirical findings provide a strong foundation for future investigations into constrained or biased random walks, including applications in fields throughout all five dimensions investigated: 1D random walks model simple transport along linear pathways, 2D random walks are relevant to modeling diffusion on surfaces or membranes, 3D correspond to true volumetric diffusion, and specific applications in statistical physics such as the Spin-Glass model [7] may be interpreted as walks in higher-dimensional spaces. These applications demonstrate the broad utility of the random walk framework.


  1. Xia, Feng, et al. “Random walks: A review of algorithms and applications.” IEEE Transactions on Emerging Topics in Computational Intelligence 4.2 (2019): 95-107
  2. Über eine Aufgabe der Wahrscheinlichkeitsrechnung betreffend die Irrfahrt im Strassennetz, Math. Ann. 84 (1921): 149-160
  3. Novak, Jonathan. “Polya’s Random Walk Theorem” 18.095 Notes (2018): 1-6
  4. Weisstein, Eric W. “Pólya's Random Walk Constants.” From MathWorld, A Wolfram Resource. mathworld.wolfram.com/PolyasRandomWalkConstants.html
  5. Weisstein, Eric W. “Random Walk, 1-Dimensional.” From MathWorld, A Wolfram Resource. mathworld.wolfram.com/RandomWalk1-Dimensional.html
  6. Jonathan M. Borwein, Dirk Nuyens, Armin Straub, James Wan. Random Walks in the Plane. 22nd International Conference on Formal Power Series and Algebraic Combinatorics (FPSAC 2010), 2010, San Francisco, United States. pp.191-202, ⟨10.46298/dmtcs.2862⟩. ⟨hal-01186291⟩
  7. Crisanti, A., Horner, H. & Sommers, H.J. The spherical p-spin interaction spin-glass model. Z. Physik B, Condensed Matter 92, 257–271 (1993). doi.org/10.1007/BF01312184