Generating 2-D random unit steps

  1. Choose theta a random number in the range [0,2pi] and then set x=cos(theta), y=sin(theta).

  2. Choose a random value for delta x in the range [-1,1] and delta y = +/- sqrt[1 - (delta x)^2] (choose the sign randomly too).

  3. Choose separate random values for delta x, delta y in the range [-1,1] (but not delta x = 0, delta y = 0). Normalize delta x, delta y so that the step size is 1.

  4. Choose a direction (N, E, S, W) randomly as the step direction (no trigonometric functions are then needed). Note, choosing one of four directions is equivalent to choosing a random integer on [0,3].

  5. Choose separate random values delta x, delta y in the range [-sqrt(2),sqrt(2)]. Although the step size is generally not 1, it becomes 1 on the average.


Although all these methods seem to be reasonable, only the last one gives us good results when we are dealing with a large number of steps.


BACK to the main document.