gotcha or bug? random state reset on irrelevant import

Alex Martelli aleax at mac.com
Tue Apr 24 23:51:59 EDT 2007


Alan Isaac <aisaac at american.edu> wrote:

> "John Machin" <sjmachin at lexicon.net> wrote in message
> news:462EB311.2010508 at lexicon.net...
> > It's not irrelevant; the test2 module has to be *executed* as part of
> > the import. [...] seed(314) is executed.
> 
> OK, I understand this is the right answer.
> But another way to look at the question is:
> is it a good design to only be able to use seed
> to set a global state? (See for contrast
> numpy.random, for which my appreciation
> has just increased yet again.)

What do you mean?  Just instantiate the random.Random class and you can
call .seed on it as well as anything else, and no other module will
infringe on "your" module's Random instance.  The "global functions" of
module random exist for those who *SPECIFICALLY* want globally shared
behavior, of course.


Alex



More information about the Python-list mailing list