R algorithm for a drunk man's walk


#1

I need to simulate a man's walk. He has a probability of p that he turns to the left and a probability of q = 1-p that he turns to the right. His step length is 1 foot. What algorith should I use to simulate this man's walk? I need this to help me plot his first 500 steps.


#2

Feels like a homework assignment...

you should create your own algorithm:

  1. draw left or right based on probability weighted draw. You could draw between c(0,1) or you could draw letters, c('L','R'). You will need something like the sample function in R. type ?sample in R to get the help page for the function.
  2. For graphing, I would use the Turtle Graphics package:
    https://cran.r-project.org/web/packages/TurtleGraphics/vignettes/TurtleGraphics.pdf

#3

if you get hung up on something, come back and ask a specific question and show what you tried. I'm happy to help if you're making an effort, but you won't learn anything if you just have someone else do it for you.