change of random state when pyc created??

Diez B. Roggisch deets at nospam.web.de
Wed May 9 09:54:55 EDT 2007


Alan Isaac wrote:

> 
> "Peter Otten" <__peter__ at web.de> wrote in message
> news:f1rt61$kfg$03$1 at news.t-online.com...
>> Alan Isaac wrote:
>> There is nothing wrong with the random module -- you get the same numbers
> on
>> every run. When there is no pyc-file Python uses some RAM to create it
>> and therefore your GridPlayer instances are located in different memory
>> locations and get different hash values. This in turn affects the order
>> in which they occur when you iterate over the GridPlayer.players_played
>> set.
> 
> Thanks!!
> This also explains Steven's results.
> 
> If  I sort the set before iterating over it,
> the "anomaly" disappears.
> 
> This means that currently the use of sets
> (and, I assume, dictionaries) as iterators
> compromises replicability.  Is that a fair
> statement?

Yes.
 
> For me (and apparently for a few others)
> this was a very subtle problem.  Is there
> a warning anywhere in the docs?  Should
> there be?

Not really, but that depends on what you know about the concept of sets and
maps as collections of course.

The contract for sets and dicts doesn't imply any order whatsoever. Which is
essentially the reason why

set(xrange(10))[0]

doesn't exist, and quite a few times cries for an ordered dictionary as part
of the standard libraries was made.

Diez



More information about the Python-list mailing list