difference between random module in python 2.6 and 3.2?
steve+comp.lang.python at pearwood.info
Mon Feb 6 00:56:23 EST 2012
On Mon, 06 Feb 2012 00:07:04 -0500, Terry Reedy wrote:
> On 2/5/2012 11:01 PM, Steven D'Aprano wrote:
>> Reading the docs, I would expect that when using an int as seed, you
>> should get identical results.
> That is similar to expecting hash to be consistent from version to
No. hash is not intended to be consistent across versions, or even across
runs of the interpreter. Of course it may be, but that's not an implicit
or explicit promise. Seeding a pseudo-random number generator, on the
other hand, is explicitly for generating the same repeatable, consistent
set of results. That's what seed is *for*.
It is even documented that way:
although the docs weasel out of promising anything other than
random.random() will be predictable.
When the Mersenne Twister was introduced, the old Wichman-Hill PRNG was
provided for those who needed repeatability. (I see it's gone now, but if
people haven't migrated their code from 2.3 yet, shame on them.)
>> There is no mention that the PRNG has changed between 2.6 and 3.2;
> There is at best an informal policy. This was discussed in
> Antoine argued that if there were a written policy, it should be limited
> to bug-fix releases within a version. I agree.
I think this thread demonstrates that there are people who depend on
repeatability of the random number routines, and not just for
I think it is ironic (and annoying) that the same release of Python that
introduced a version argument to seed() to provide a backward compatible
seeding algorithm, also introduced a backward incompatible change to
This, plus Raymond Hettinger's comments on the bug report, make me think
that the change in behaviour of randrange and choice is not deliberate
and should be treated as a bug. Raymond made a strong case arguing for
repeatability, and then approved a bug fix that broke repeatability. I
doubt that was deliberate.
More information about the Python-list