On Sun, Jun 10, 2018 at 11:53 PM, Ralf Gommers <ralf.gomm...@gmail.com> wrote:
>
> On Sun, Jun 10, 2018 at 11:15 PM, Robert Kern <robert.k...@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
>
> old_state = np.random.get_state()
> np.random.seed(some_int)
> do_stuff()
> np.random.set_state(**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
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to