1

I've been trying to create a 2D random walk process for my project. The question is as follows, Create a 2-dimensional random walk process where the walker can move up, down, left, or right. The walker should have an equal chance of going in any direction (25%). Create a graph of a single walk.

We've been using these functions but I'm unsure how to go about it correctly.

`A = Table[0, {1}, {2}];
Do[
 x = RandomReal[];
 Which[
  x < 0.25, A[[i + 1, 1]] = A[[i, 1]] + 1;
  x < 0.25, A[[i + 1, 2]] = A[[i, 2]] - 1],
 {i, 1, 0}, {i, 1, 1}]
ListLinePlot[A]` 

It's supposed to look like this. Thanks

enter image description here

1 Answers1

4

For unbounded area, the following should work

ListLinePlot[Accumulate@RandomChoice[{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}, 500]]
xieyn
  • 143
  • 6