Global Random Seed
See original GitHub issueHi,
First and foremost thanks for a great package!
I have a short question about whether or not it is possible to set a global random seed for numba?
I have a main file which uses a bunch of numba functions defined in other files. Most of these external numba functions make use of np.random
and I would thus like to set a global random seed.
I have tried setting os.environ['PYTHONHASHSEED'] = str(seed)
in the main file, however, this does not work (the numba functions change output from run to run).
Note that I am running the file through VS Code, so, as far as I know, I cannot set environmental variables in other ways.
If I define np.random.seed(seed)
in each of the numba functions (and add the extra variable seed
to the function), it works. This method, however, is cumbersome and does not seems like the optimal way.
I hope that you can help!
Cheers,
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Thanks for the report, glad to hear you like Numba!
From memory, in Numba the RNG seeds are held in thread local storage, so if the code is single threaded it should be possible to call the seed setting function once at the start of the program and then it’ll be reproducible across runs. Example:
running this repeatedly:
Great, thanks, much appreciated!