Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Size of seeds for numpy.random

I want to run some code using numpy.random and keep track of what the seed is so that if the output is interesting, I can recreate and play around with that randomly generated instance. Therefore, I want the setup to involve something like

import numpy as np
s = np.random.randint(10000000000)
print(s)
np.random.seed(s)
### remainder of code

so that the code is still running randomly, but I also have retained the seed s. The value 10000000000 was chosen arbitrarily; what is the appropriate scale for numpy.random‘s seeding? e.g. are seeds all the same modulo 2^32?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Personally, I’d use the time as a seed or SHA-256 as it’s a standard rather than just a 32-bit int, here is an example of how to use the time, depending on your usecase.

import numpy as np
import time

# Use current time as seed value
s = int(time.time())
print("Seed value:", s)

np.random.seed(s)
# Generate random numbers
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading