Random Walk 1D

Program RandomWalk1d allows you to explore the properties of random walks in one dimension. Random walks are an example of a Bernoulli process for which there are two possible independent events (a step to the right or to the left). The distribution of walks in a particular direction is given by the binomial distribution. In addition, random walks are models of diffusion.

ProblemMonte Carlo simulation of a one-dimensional random walk Program RandomWalk1d simulates a random walk in one dimension. A walker starts at the origin and takes $N$ steps. At each step the walker goes to the right with probability $p$ or to the left with probability $q = 1 - p$. Each step has the same unit length and is independent of the previous steps. Are some displacements more likely than others? We can simulate an $N$-step walk by the following pseudocode:

do istep = 1,N

$\,\,\,\,$if (rnd <= p) then

$\,\,\,\,\,\,\,\,$x = x + 1


$\,\,\,\,\,\,\,\,$x = x - 1

$\,\,\,\,$end if

end do

The function rnd generates a number between zero and one with equal probability. The quantity $x$ is the net displacement after $N$ steps assuming that the steps are of unit length.

We average over many walkers (trials), where each trial consists of a $N$ step walk and construct a histogram for the number of times that the displacement $x$ is found. The probability that the walker is a distance $x$ from the origin after $N$ steps is proportional to the corresponding value of the histogram. This procedure is called Monte Carlo sampling.

  1. Is the value of $x$ for one trial of any interest? Why do we have to average over many trials?
  2. Will we obtain the exact answer for the probability distribution by doing a Monte Carlo simulation?
  3. How does the histogram change for larger values of $N$. Assume $p=1/2$ here and in the following.
  4. What is the most probable value of $x$ for $N = 16$ and $N = 32$? Estimate the width of the distribution visually. How does the width change as a function of $N$?
  5. How does the histogram change, if at all, as the number of walkers increases for $N=4$?


Problem 3.41 in Statistical and Thermal Physics: With Computer Applications, 2nd ed., Harvey Gould and Jan Tobochnik, Princeton University Press (2021).

OSP Projects:
Open Source Physics - EJS Modeling - Tracker - Physlet Physics - Physlet Quantum Physics - STP Book