tests/old/rw2d.R

# This is Ross' 2D random walk again.
#
rw2d1 =
function(n = 100)
{
    xpos = ypos = numeric(n)
    for(i in 2:n) {
          # Decide whether we are moving horizontally or vertically.
      delta = if(runif(1) > .5) 1 else -1
      if (runif(1) > .5) {
        xpos[i] = xpos[i-1] + delta
        ypos[i] = ypos[i-1]
      }
      else {
        xpos[i] = xpos[i-1]
        ypos[i] = ypos[i-1] + delta
      }
    }
    list(x = xpos, y = ypos)
}
duncantl/RTypeInference documentation built on Jan. 16, 2021, 12:30 a.m.