gotcha or bug? random state reset on irrelevant import

Alan Isaac aisaac at american.edu
Wed Apr 25 10:41:16 EDT 2007


Alex Martelli said:
> 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.


I consider this an unduly kind response.
"RTFM" would have been appropriate.

     The functions supplied by this module are actually bound
      methods of a hidden instance of the random.Random class.
     You can instantiate your own instances of Random to get generators that
don't share state.

Sheesh.  I must have been asleep when reading the documentation.

Thanks,
Alan





More information about the Python-list mailing list