Random Walk—3-Dimensional

Author

Eric W. Weisstein
December 17, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Statistics/RandomWalk3-Dimensional.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/RandomWalk3-Dimensional.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

3-D Lattice

RandomWalk3DLattice[N_]:=Module[{l={{0,0,0}},x={0,0,0},r},
  Do[
    r=Random[];
    x+=Which[
      r<=1/6,{1,0,0},
      r<=2/6,{0,1,0},
      r<=3/6,{0,0,1},
      r<=4/6,{-1,0,0},
      r<=5/6,{0,-1,0},
      r<=6/6,{0,0,-1}
    ];
    l=Append[l,x],
    {N}
  ];
  l
]

rw=RandomWalk3DLattice[100];
Show[Graphics3D[{Line[rw],{PointSize[.05],Point[rw[[-1]]]}},Axes->True],AspectRatio->Automatic]]

<<UtilitiesLiveGraphics3D`

WriteLiveForm["random3.m",%]