What is the best way to generate uniform random numbers (e.g a double in [0, 1)) that is:
- Cross platform (ideally with same same sample sequence)
- Thread safe (explicit passing of the mutated state of the prng or using a thread-local state internally)
- No GIL lock
- Easily wrappable in Cython
There was a similar post over 3 years ago about this but a lot of the answers don't meet all criteria. For example, drand48 is POSIX-specific.
The only method I'm aware of that seems (but not sure) to meet all criteria is:
from libc.stdlib cimport rand, RAND_MAX
random = rand() / (RAND_MAX + 1.0)
Note @ogrisel asked the same question about 3 years ago.
Aucun commentaire:
Enregistrer un commentaire