home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / PROGRAMM.PAK / RANDOMWA.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  740 b   |  31 lines

  1.  
  2. (*********************************************************************
  3.  
  4.         Adapted from
  5.         Roman E. Maeder: Programming in Mathematica,
  6.         Second Edition, Addison-Wesley, 1991.
  7.  
  8.  *********************************************************************)
  9.  
  10.  
  11. BeginPackage["RandomWalk`"]
  12.  
  13. RandomWalk::usage = "RandomWalk[n] plots a random walk of length n."
  14.  
  15. Begin["`Private`"]
  16.  
  17. range = N[{0, 2Pi}]
  18.  
  19. RandomDelta[] := With[{dir = Random[Real, range]}, {Cos[dir], Sin[dir]}]
  20.  
  21. RandomWalk[n_Integer] :=
  22.     Module[{points},
  23.         points = NestList[ # + RandomDelta[]&, {0.0, 0.0}, n];
  24.         Show[ Graphics[{Point[{0,0}], Line[points]}],
  25.               Frame->True, FrameTicks->None, AspectRatio->1 ]
  26.     ]
  27.  
  28. End[]
  29.  
  30. EndPackage[]
  31.