[Numpy-discussion] reseed random generator (1.19)
robert.kern at gmail.com
Mon Jun 29 10:51:23 EDT 2020
On Mon, Jun 29, 2020 at 8:02 AM Neal Becker <ndbecker2 at gmail.com> wrote:
> I was using this to reset the generator, in order to repeat the same
> sequence again for testing purposes.
In general, you should just pass in a new Generator that was created with
the same seed.
x = rg.standard_normal()
SEED = 12345...
rg = np.random.default_rng(SEED)
rg = npp.random.default_rng(SEED)
Resetting the state of the underlying BitGenerator in-place is possible, as
Kevin showed, but if you can refactor your code so that there isn't a
persistent Generator object between these runs, that's probably better.
It's a code smell if you can't just pass in a fresh Generator; in general,
it means that your code is harder to use, not just because we don't expose
an in-place seed() method.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion