[Python-Dev] a note in random.shuffle.__doc__ ...

Terry Jones terry at jon.es
Sun Jun 11 03:04:38 CEST 2006


>>>>> "Greg" == Greg Ewing <greg.ewing at canterbury.ac.nz> writes:
Greg> A generator with only N possible internal states can't
Greg> possibly result in more than N different outcomes from
Greg> any algorithm that uses its results.

I don't mean to pick nits, but I do find this a bit too general.

Suppose you have a RNG with a cycle length of 5. There's nothing to stop an
algorithm from taking multiple already returned values and combining them
in some (deterministic) way to generate > 5 outcomes. (Yes, those outcomes
might be more, or less, predictable but that's not the point). If you
expanded what you meant by "internal states" to include the state of the
algorithm (as well as the state of the RNG), then I'd be more inclined to
agree.

Worse, if you have multiple threads / processes using the same RNG, the
individual threads could exhibit _much_ more random behavior if individual
thread outcomes depend on multiple RNG return values (as is the case with
random.shuffle) and the scheduler is mixing things up. Here you'd have to
include the state of the operating system to claim you can't get more
outcomes than the number of internal states. But that's getting pretty far
away from what we'd ordinarily think of as the internal state of the RNG.

Terry


More information about the Python-Dev mailing list