! From: "COMPUTATIONAL PHYSICS, 2nd Ed" ! by RH Landau, MJ Paez, and CC Bordeianu ! Copyright Wiley - VCH, 2007. ! Electronic Materials copyright: R Landau, Oregon State Univ, 2007; ! MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. ! Supported by the US National Science Foundation ! ! walk.f90:RanDom walk simulation Program walk Implicit none Real*8 :: ranDom, root2, x, y, r(1:10000) Integer :: i, j, max max = 10000 ! set parameters (# of steps) root2 = 1.4142135623730950488E0 open(6, FILE = 'walk.dat', Status = 'Unknown') ! open file ! clear array Do j = 1, max r(j) = 0 End Do ! average over 100 trials Do j = 1, 100 x = 0. y = 0. Do i = 1, max x = x + (ranDom() - 0.5)*2.0*root2 y = y + (ranDom() - 0.5)*2.0*root2 r(i) = r(i) + Sqrt(x*x + y*y) End Do End Do ! output data for plot of r vs. sqrt(N) Do i = 1, max Write (6, *) Sqrt(Real(i)), ' ', r(i)/100 End Do close(6) Stop 'data saved in walk.dat' End Program walk