gotcha or bug? random state reset on irrelevant import

James Stroud jstroud at mbi.ucla.edu
Tue Apr 24 21:33:13 EDT 2007


Alan Isaac wrote:
> Running test.py will print False.
> Is this expected/desirable?
> Thanks,
> Alan Isaac
> 
> 
> %%%%%%% test.py %%%%%%%%%%%
> from random import seed, getstate
> seed(217)
> x = getstate()
> from test2 import Trivial
> y = getstate()
> print x == y
> 
> 
> %%%%%  test2.py  %%%%%%%%%%%%%
> from random import seed
> seed(314)
> class Trivial:
>     pass
> 
> 
> 

Yes. To circomvent this, use

from random import seed

class Trivial:
   pass

if __name__ == "__main__":
   seed(314)



More information about the Python-list mailing list