c From: "COMPUTATIONAL PHYSICS, 2nd Ed" c by RH Landau, MJ Paez, and CC Bordeianu c Copyright Wiley-VCH, 2007. c Electronic Materials copyright: R Landau, Oregon State Univ, 2007; c MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. c Support by National Science Foundation c c walk.f: random walk simulation c If your compiler complains about drand48, seed48, c replace drand48 with rand(seed) and remove call to seed48 c Data output as sqrt(steps), distance c Program walk Implicit none Real*8 drand48, root2, theta, x, y, r(1:10000) Integer i, j, max, seed c set parameters (# of steps) max = 10000 seed = 11168 root2 = 1.4142135623730950488E0 c open file, seed generator Open(6, file = 'walk.dat', Status = 'Unknown') Call seed48(seed) c clear array Do 1 j = 1, max r(j) = 0 1 Continue c average over 100 trials Do 10 j = 1, 100 x = 0 y = 0 c take max steps Do 20 i = 1, max x = x + (drand48()-0.5)*2.*root2 y = y + (drand48()-0.5)*2.*root2 r(i) = r(i)+ Sqrt(x * x + y * y) 20 Continue 10 Continue c output data for plot of r vs. sqrt(N) Do 30 i = 1, max Write (6, *) Sqrt(Real(i)), ' ', r(i)/100 30 Continue Close(6) Stop 'data saved in walk.dat' End