I have these functions
Randomwalk1[n_] :=Accumulate[2*RandomInteger[{0, 1}, n] - 1];
Randomwalk2[n_] := NestList[# + 2*RandomInteger[{0, 1}] - 1 &, 0, n]
that are random walks in 1D and I have to modify them to get a random walk in 2D, the walker can move right, left, step back or move forward with same probability 1/4 .. I'm a beginner and really don't know how to do that..
Thanks
I was thinking about an other way to do that without using these functions but I don't know if it can work and don't know how to do that in mathematica, here is the idea
if RandomInteger[{1,2}]=1
the walker moves in x direction
and if RandomInteger[{1,2}]=2
the walker moves in y direction
Then we call 2*RandomInteger[{0, 1}] - 1
to randomly generate -1 or +1 and the walker makes this step in the direction that was first determined
RandomChoice[]
? $\endgroup$data2d = RandomFunction[RandomWalkProcess[0.5], {0, 10^3}, 2]; Graphics[Line[Transpose@data2d["States"]], AspectRatio -> Automatic]
$\endgroup$RandomChoice
as suggested by @J.M.:randomwalk[n_] := Accumulate[RandomChoice[{-1, 1}, n]]
. The extension to the 2D case that you are asking for would read:randomwalk2d[n_] := Accumulate[RandomChoice[{-1, 1}, {n, 2}]]
. $\endgroup$