mercredi 29 janvier 2020

Numpy Gaussian from /dev/urandom

I have an application where I need numpy.random.normal but from a crypgoraphic PRNG source. Numpy doesn't seem to provide this option.

The best I could find was numpy.random.entropy.random_entropy but this is only uint32 and it's buggy, with large arrays you get "RuntimeError: Unable to read from system cryptographic provider" even though urandom is non-blocking...

You can however do this: np.frombuffer(bytearray(os.urandom(1000*1000*4)), dtype=np.uint32).astype(np.double).reshape(1000, 1000)

But I'm still left with the problem of somehow converting it to a Guassian and not screwing anything up.

Is there a solution someone knows? Google is poisoned by numpy seeding from /dev/urandom, I don't need seeding, I need urandom being the only source of all randomness.




Aucun commentaire:

Enregistrer un commentaire