## ats606/

# ats_random_walk.pro

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....)

## Examples

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'
```

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

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

- History
Modification History:

`First written: April 11, 2014 PMB`

## Other file information

- Uses:
None

## Routines

## 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.

### Parameters

- n in optional type=integer default=100
Number of steps in the random walk

### Keywords

- 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

- Uses:
None

## File attributes

Modification date: | Wed Apr 23 13:24:42 2014 |

Lines: | 42 |

Docformat: | rst rst |