title: How to generate random directions (N, S, E, W, none) with some kind of "momentum"?
body: <p>I'm trying to perform explore a grid in a random fashion.<br>
  The five possible directions I can go are north, east, south, west, and stay, all of which are equally likely, at least initially.</p>
  
  <p>The trouble with simply choosing a random direction from the above is that it ends up keeping my agent too close to the center (two random directions can cancel each other out very easily), which completely defeats the purpose of the random walk.</p>
  
  <p>What I would <em>like</em> to do is to generate random directions in a random fashion that is unbiased as a whole, but which <em>is more likely to choose a direction close to the the previously chosen direction</em>.  </p>
  
  <p>Put another way, I need my RNG to have some kind of "momentum".</p>
  
  <p>I came up with this algorithm:</p>
  
  <pre><code>def RandomWithMomentum(n, momentum=0.5):
      from random import uniform
      v = uniform(-1, 1)
      for i in range(n):
          yield v
          v = v * momentum + uniform(-1, 1) * (1 - momentum)
  </code></pre>
  
  <p>which seems to give excellent results:</p>
  
  <pre><code>-0.04367186243339227
  -0.1798381656787107
  -0.07608795741137708
  -0.0728742899528114
  -0.06215075604982321
   0.17952360050689026
   0.016352984710556573
   0.16954506853320414
   0.3947467183848671
   0.12785652121165636
  </code></pre>
  
  <p>... except that while this algorithm guarantees that positive and negative numbers are equally likely, it does <em>not</em> guarantee a uniform distribution in the interval from -1 to +1!</p>
  
  <p>(This should be obvious if you realize that the numbers aren't necessarily bounded by -1 and +1!)</p>
  
  <p>So my question is, how would I extend this (or some other algorithm) to choosing one of the five <em>directions</em>, instead of just a positive or negative number?</p>