# Genarating Random Move right left up down

Suppose that we have a 4 faces die. The person toss the die and if it land on:
1) the person will move to the right
2) the persone will move to the left
3) the person will move upward
4) the person will move downward

The process will repeat again by tossing the coin and move from the last position and so on for n more times.

How can I generate this random simulation.

test[n_] := Accumulate[RandomChoice[{{-1, 0}, {1, 0}, {0, 1}, {0, -1}}, n]]


How can i show the last point that it is plot if I use this function ListLinePlot[test]?

• Look at RandomChoice Oct 5, 2015 at 2:10
• Oct 5, 2015 at 2:20
• Oct 5, 2015 at 2:25
• test[n_] := Accumulate[RandomChoice[{{-1, 0}, {1, 0}, {0, 1}, {0, -1}}, n]], How can i plot this, Oct 5, 2015 at 2:37
• ListLinePlot[#, PlotRange -> All, Mesh -> All, Epilog -> {Red, Point@Last@#}, AspectRatio -> Automatic] &@test Oct 5, 2015 at 3:14

You might implement your random walk something like this.

walk[n_] :=
Prepend[
Accumulate[RandomChoice[{{-1, 0}, {1, 0}, {0, 1}, {0, -1}}, n]],
{0, 0}]

trial[n_] :=
Module[{path, start, end},
path = walk[n];
start = First @ path;
end = Last @ path;
ListLinePlot[path,
Epilog -> {PointSize[Large], Point[start], Red, Point[end]},
AspectRatio -> Automatic]]

SeedRandom; trial 