1
$\begingroup$

This question already has an answer here:

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

$\endgroup$

marked as duplicate by Kuba Apr 24 '18 at 6:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Perhaps you could draw inspiration from previously asked questions on this site (use the search bar at the top of the page). For instance, this question and its answers might be a good start: 2D random walk within a bounded area. $\endgroup$ – MarcoB Apr 24 '18 at 4:00
  • $\begingroup$ Okay, thank you. $\endgroup$ – Kayla Stith Apr 25 '18 at 3:23
4
$\begingroup$

For unbounded area, the following should work

ListLinePlot[Accumulate@RandomChoice[{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}, 500]]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.