module random: delay in "seeding"

Alex Martelli aleax at aleax.it
Sat May 4 02:17:30 EDT 2002


Roman Suzi wrote:
        ...
> While it is quite understandable that normally distributed numbers
> come in pairs, but I thought seed() resets the state of random module...

No, you need getstate and setstate methods for that.  If all you want
is to also reset the gauss_next attribute, go ahead -- no leading
underscore, so it's public.  Note that getstate returns the version (to
check if you ever try to restore state to an incompatible version),
seed, and gauss_next.  They're also exposed as __getstate__ and
__setstate__ so you may ALSO pickle/unpickle random.Random
instances and also copy.copy them.

> I think this sometimes can cause errors.

If so, then the docs need to be made clearer; it seems to me that
the mechanisms are just fine.


Alex




More information about the Python-list mailing list