title: How to optimize a for loop that uses consecutive values with Numpy?
body: <p>I'm trying to create a function that returns a <code>numpy.array</code> with <code>n</code> pseudo-random uniformly distributed numbers between 0 and 1. The details of the method used can be found here: <a href="https://en.wikipedia.org/wiki/Linear_congruential_generator" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Linear_congruential_generator</a></p>
  
  <p>So far, it works great. The only problem is that each new value is calculated by using the previous value, so the only solution I've found so far uses a loop, and for the sake of eficiency I'm trying to get rid of that loop, possibly by vectorizing the operation - however, I don't know how to do so.</p>
  
  <p>Do you have any suggestions on how to optimize this function?</p>
  
  <pre><code>import numpy as np
  import time
  
  def unif(n):
      m = 2**32
      a = 1664525
      c = 1013904223
  
      result = np.empty(n)
      result[0] = int((time.time() * 1e7) % m)
  
      for i in range(1,n):
          result[i] = (a*result[i-1]+c) % m
  
      return result / m
  </code></pre>