(*********************************************************************

Copyright 1989 by Roman E. Maeder

Adapted from
Roman E. Maeder: Programming in Mathematica, Addison-Wesley, 1989.

Permission is hereby granted to make copies of this file for
any purpose other than direct profit, or as part of a
commercial product, provided this copyright notice is left
intact. Sale, other than for the cost of media, is prohibited.

Permission is hereby granted to reproduce part or all of
this file, provided that the source is acknowledged.

*********************************************************************)

BeginPackage["RMPackages`RandomWalk`"]

RandomWalk::usage = "RandomWalk[n] plots a random walk of length n."

Begin["`Private`"]

RandomWalk[n_Integer] :=
Block[{loc = {0.0, 0.0}, dir, points = Table[0, {n+1}], range = N[{0, 2Pi}]},
points[[1]] = loc;
Do[
dir = Random[Real, range];
loc += {Cos[dir], Sin[dir]};
points[[i]] = loc,
{i, 2, n+1}];
Show[ Graphics[{Point[{0,0}], Line[points]}],
Framed->True, AspectRatio->1 ]
]

End[]

Protect[ RandomWalk ]

EndPackage[]