Skip to content

Instantly share code, notes, and snippets.

@reem
Forked from supercavitation/gist:6433123
Last active December 22, 2015 06:48
Show Gist options
  • Save reem/6433141 to your computer and use it in GitHub Desktop.
Save reem/6433141 to your computer and use it in GitHub Desktop.
import numpy.random as nprnd
from time import clock
def r_step_generator(lo, hi):
num = lo
diff = hi - lo
while True:
num += nprnd.randint(0, diff)
if num < hi:
yield num
else:
raise StopIteration
N = 10 ** 7
t1 = clock()
u = range(0, (N // 100) * 99)
x = nprnd.randint(0, N, N // 100)
for i_x, i_u in enumerate(r_step_generator(0, N)):
u.insert(i_u, x[i_x])
t2 = clock()
print t2 - t1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment