Program drunkards_walk !------------------------------------------------------------------------------ !Program: Drunkard's Walk !Author: Chris Harper !Date: 3/6/2008 !------------------------------------------------------------------------------ IMPLICIT NONE !declarations integer :: i, j integer :: pos, home_count, pub_count, rolls real :: roll_avg, random(SIZE) integer :: time_array(8), seed(1) !initialize the random number generator call date_and_time(values = time_array) seed(1) = time_array(8) call random_seed(put =, SIZE !output a header print *, "Drunkard's Walk" print "(A9, T12, A10, T24, A5, T30, A6)", & "Start Pos", "Avg Blocks", "% Pub", "% Home"do i = 2, 7 !starting point home_count = 0 pub_count = 0 roll_avg = 0 do j = 1, 500 !500 tests per starting point rolls = 0 pos = i do rolls = rolls + 1 call random_number(random) if (random < (2.0/3.0)) then pos = pos - 1 else pos = pos + 1 end if if (pos == 8) then home_count = home_count + 1 exit else if (pos == 1) then pub_count = pub_count + 1 exit end if if (rolls > 1000) exit !iteration cap end do !Current_Avg = ((Prev_Avg * Prev_Count) + New_Value) / New_Count roll_avg = ((roll_avg * (j-1)) + rolls) / j end do print "(I9, T12, F10.4, T24, F5.1, T31, F5.1)", i, roll_avg, & ((pub_count/500.0)*100), ((home_count/500.0)*100) end do end