# (c) Rory Clune 2/23/2011 # Random Walker with order Linear Congruential random number generator. Error bars derived analytically from numpy import* from pylab import* rand = 1 #seed for random number generation points = 1000 #number of random steps that will be taken walkers = 1 x = zeros([1000]) for i in range (0,walkers): for j in range (1,points): #Generate the next random number (linear congruential) in the range [1, 134456] rand = ((8121*rand + 28411)%134456) if rand < (134456/2): x[j]=x[j-1]+1 else: x[j]=x[j-1]-1 plot(x) t = arange(0,points,(points/5)) error = 1.5*sqrt(t) errorbar(t, zeros([size(t)]), yerr=error, fmt=None, ecolor = 'k') axis([0,points,-150,150]) show() print x