Random Walks

A random walk is an interesting type of simulation which is fairly straightforward to understand, and surprisingly pretty useful. I’ll explain the concept by way of a silly analogy — sometimes a random walk is described as a “drunkard’s walk” where you could imagine a drunkard stumbling through a town, and when he reaches an intersection he randomly goes in one of the four possible directions. Repeat the process as many times as you like, and at the end you have yourself a random walk. Now you might think that the drunkard wouldn’t get anywhere if you repeated the process enough times he’d usually end up back where he started as the moves cancel out. This actually isn’t the case at all (however if you average over many independent walks you find that it does average out to zero).

Random walks have a variety of applications in biology, physics, and even your follower recommendations on Twitter. One of Albert Einstein’s many contributions to physics was discovering that this sort of “drunkard’s walk” is very closely related to something called Brownian motion which has to do with the seemingly random motion of microscopic objects.

One small note: what I have described so far is actually a two dimensional random walk, but you could image doing this in one dimension where the walker can only go left or right, three dimensions (up/down, right/left, backwards/forwards), or more generally in n-dimensions. Indeed there are lots of interesting variations you can make such as having some directions be slightly more likely than others (this is known as a biased random walk), or not allowing the path to revisit a point it’s already been to (this is known as a self-avoiding walk).

I made some graphs for the simple 2D random walk case. The first graph just has the walker making 1000 moves, and even with this amount you can see some pretty interesting patterns emerging. Note that in all of the graphs if you locate the point (0, 0) on the graph, that is the starting point for the journey.


The remaining three graphs are the same thing as above, but for 100,000 steps. As you can see below, each pattern obtained from this process is unique and interesting.

rand_walk100000_prettyrand_walk100000_narrow rand_walk100000_niceHere is the Python source code to generate these plots. Even if you don’t know much about programming it might still be interesting to see how very simple the code used to generate these seemingly complicated plots is! As usual, you will need Python 2.7, NumPy, and matplotlib for the script to run.


3 thoughts on “Random Walks”

  1. Excellent site you’ve got here.. It’s difficult to find high-quality writing like yours these days.
    I really appreciate individuals like you! Take care!!

Leave a Reply

Your email address will not be published.