Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the seed of a numpy `Generator`? [duplicate]

I am using rng = np.random.default_rng(seed=None) for testing purposes following documentation.

My program is a scientific code, so it is good to have some random values to test it, but if I found a problem with the code's result, I would like to get the seed back and try again to find the problem. Is there any way to do that?

Things like this question does not seem to work with a Generator:

AttributeError: 'numpy.random._generator.Generator' object has no attribute 'get_state'

Of course I can always try a set of predefined seeds, but that is not what I want.

like image 303
Abel Gutiérrez Avatar asked Nov 02 '25 19:11

Abel Gutiérrez


1 Answers

I don't remember if there is a method to get the seed directly. But alternatively you can generate a random number first, print it in logs and then set that number as seed for the rest of the program.

like image 179
Kasonnara Avatar answered Nov 04 '25 09:11

Kasonnara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!