\ Simulation of Drunkard's Walk in 2 space dimensions \ \ --------------------------------------------------- \ (c) Copyright 2000 Julian V. Noble. \ \ Permission is granted by the author to \ \ use this software for any application pro- \ \ vided this copyright notice is preserved. \ \ --------------------------------------------------- \ This is an ANS Forth program requiring the \ FLOAT, FLOAT EXT, FILE and TOOLS EXT wordsets. \ \ Environmental dependences: \ Assumes independent floating point stack MARKER -walk needs prng.f \ needs arrays.f \ Words for splitting a 32-bit integer into 16-bit parts: \ n = x*2^16 + y \ HEX 10000 CONSTANT 2^16 DECIMAL \ : split ( n -- x y) 2^16 /MOD ; \ 1000 CONSTANT Nmax \ Nmax long 1 CELLS 1array pos{ \ integer-valued vector of \ visited points 0.1 seed 2! \ initialize prng 0 VALUE x_now 0 Value y_now : new_point \ move to a new location prng 4e0 f* F>S CASE 0 OF x_now 1+ TO x_now ENDOF 1 OF x_now 1- TO x_now ENDOF 2 OF y_now 1+ TO y_now ENDOF 3 OF y_now 1- TO y_now ENDOF ENDCASE ; : walk \ perform the random walk 0 TO x_now 0 TO y_now \ initialize 0 DO new_point cr x_now . y_now . LOOP ;