Univeristy of Alabama in Huntsville


IDL Routines from Phillip Bitzer and UAH Lightning Group

summary     class     fields     routine details     file attributes



Statistics, ATS606, Random Walk

includes main-level program

A simple one dimensional random walk is an example of a Markov Chain. In a random walk, you take n steps. At each step, you can go left or right. The probability you go right at any step is p.

This routine simulates the random walk. The random number sequence used is based on the system time when you run the routine, down to the millisecond.

See ATS606 for more about random walks.

For the underlying code, we take "right" to be positive and "left" to be negative.

Right now, the random walk starts at zero (and this point is included in the returned array). From there, we take n steps. Hence, the returned array has n+1 elements.

(BTW, you could modify this slightly to have the starting location wherever you want....)


Provide an example:

nSteps = 500 location = ATS_RANDOM_WALK(nSteps, p=0.5, LEFTRIGHT=lr) steps = FINDGEN(nSteps+1) cgPlot, steps, location, XTITLE='Step Number', YTITLE='Location'
You should get somthing that looks like this:

See the main level program for more (uses Coyote Graphics). When you run the main level program, you can make an animation that might look like this:

Author information


Phillip M. Bitzer, University of Alabama in Huntsville, pm.bitzer "AT" uah.edu


Modification History:

First written: April 11, 2014 PMB

Other file information




top ats_random_walk

result = ats_random_walk( [n] [, P=float between 0 and 1], LeftRight=array of `n` elements)

This will return an array of n+1 locations based on a 1d random walk. See full documentation for more.

Return value

A n+1 element long integer array of locations along one dimension.


n in optional type=integer default=100

Number of steps in the random walk


P in optional type=float between 0 and 1 default= 0.5

The probability that the walk goes right. Formally, the transition probability of i->i+1.

LeftRight out type=array of `n` elements default= 0.5

This array tells you, at each, step, if you went left (-1) or right (+1). Useful for diagnostics.

Other attributes



File attributes

Modification date: Wed Apr 23 13:24:42 2014
Lines: 42
Docformat: rst rst