module random: delay in "seeding"

Tim Peters tim.one at comcast.net
Sat May 4 01:53:28 EDT 2002


[Roman Suzi]
> I've noticed the following:
>
> >>> import random
> >>> random.seed(123)
> >>> print random.gauss(12,12)
> 7.46167701922
> >>> random.seed(123)
> >>> print random.gauss(12,12)
> -6.54391487521
> >>> random.seed(123)
> >>> print random.gauss(12,12)
> 7.46167701922
> >>> random.seed(123)
> >>> print random.gauss(12,12)
> -6.54391487521
>
> While it is quite understandable that normally distributed numbers
> come in pairs, but I thought seed() resets the state of random module...
> I think this sometimes can cause errors.

I agree, but it's one of those things that can't be changed without risking
breaking code relying on the broken behavior (which has been broken
forever).  If you get unanimous agreement from all the usual c.l.py suspects
that they won't piss and moan if I fix it, I will.

While I'm holding my breath <wink>, you can fix it in your copy of a recent
random.py by adding

        self.gauss_next = None

to the end of Random.seed.






More information about the Python-list mailing list