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

Tim Peters tim.peters at gmail.com
Mon Jun 12 05:25:53 CEST 2006


[Terry Jones]
> The code below uses a RNG with period 5, is deterministic, and has one
> initial state. It produces 20 different outcomes.

Well, I'd call the sequence of 20 numbers it produces one outcome.
>From that view, there are at most 5 outcomes it can produce (at most 5
distinct 20-number sequences).  In much the same way, there are at
most P distinct infinite sequences this can produce, if the PRNG used
by random.random() has period P:

def belch():
    import random, math
    start = random.random()
    i = 0
    while True:
        i += 1
        yield math.fmod(i * start, 1.0)

The trick is to define "outcome" in such a way that the original claim
is true :-)


More information about the Python-Dev mailing list