# # walker.py # # Plots 1D Random Walks # # Carlos Rocha - February 2005 ############################## from time import * from numarray import * from pylab import * # Random Number Generator ############################## class RandStep: def __init__(self): self.seed = int(time()) # Initial Random Seed def next(self): """Returns a random step of size 1, using a LCG""" self.seed = (8121 * self.seed + 28411) % 134456 if (self.seed > 67228): return 1 else: return -1 # Random 1D Walker ############################## def main() : pcount = 10 # Number of particles points = 1000 # Number of points rand = RandStep() ps = zeros((pcount,points)) # Draw particles for i in range(pcount): for j in range(1,points): ps[i][j]=ps[i][j-1] + rand.next() plot(ps[i]) # Draw errorbars for x in range(points/100): errorbar(x*100,0,yerr=3*sqrt(x*100)) title("1D Random Walkers") axis([0, 1000, -70, 70]) show() if __name__ == "__main__" : main()