[Numpy-discussion] NEP: Random Number Generator Policy (original) (raw)
Nathaniel Smith njs at pobox.com
Mon Jun 11 03:45:39 EDT 2018
- Previous message (by thread): [Numpy-discussion] NEP: Random Number Generator Policy
- Next message (by thread): [Numpy-discussion] NEP: Random Number Generator Policy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Jun 10, 2018 at 11:53 PM, Ralf Gommers <ralf.gommers at gmail.com> wrote:
On Sun, Jun 10, 2018 at 11:15 PM, Robert Kern <robert.kern at gmail.com> wrote:
The intention of this code is to shuffle two same-length sequences in the same way. So now if I write my code well to call np.random.seed() once at the start of my program, this function comes along and obliterates that with a fixed seed just so it can reuse the seed again to replicate the shuffle. Yes, that's a big no-no. There are situations conceivable where a library has to set a seed, but I think the right pattern in that case would be something like oldstate = np.random.getstate() np.random.seed(someint) dostuff() np.random.setstate(**old.state)
This will seem to work fine in testing, and then when someone tries to use your library in a multithreaded program everything will break in complicated and subtle ways :-(. I really don't think there's any conceivable situation where a library (as opposed to an application) can correctly use the global random state.
-n
-- Nathaniel J. Smith -- https://vorpus.org
- Previous message (by thread): [Numpy-discussion] NEP: Random Number Generator Policy
- Next message (by thread): [Numpy-discussion] NEP: Random Number Generator Policy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]