Reputation: 2274
Basically I need over a million points on x-y plane. I am thinking about first generating 1 million points in range -x to x, another million in range y to -y and then coupling them together. What will be optimized and fast way to do this? In random.randrange good enough?
Upvotes: 0
Views: 202
Reputation: 500267
I would use NumPy for that. In my quick test numpy.random.uniform()
is over 60 times faster than calling random.randrange()
in a loop.
In [12]: %timeit [random.randrange(-10, 10) for _ in range(2000000)]
1 loops, best of 3: 2.95 s per loop
In [13]: %timeit numpy.random.uniform(-10, 10, (1000000, 2))
10 loops, best of 3: 43.8 ms per loop
Upvotes: 1