samedi 22 juin 2019

Numba and Numpy Random Number interaction

I am trying to generate a bunch of random numbers quickly to do a MCMC.

I have the following benchmarks:

@njit
def getRandos(n):
    for i in prange(n):
        a = np.random.rand()


%timeit np.random.rand(1000000000)
13.1 s ± 287 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

%timeit getRandos(1000000000)
1.97 s ± 25.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

Clearly the parallelization improves my runtime. However, I don't know how the seeding of the random number generation works. How can I ensure that these numbers are truly random? Do I have to randomly choose a seed somehow?




Aucun commentaire:

Enregistrer un commentaire