Does shuffle() produce uniform result ?

Alex Martelli aleax at mac.com
Sun Aug 26 01:14:37 EDT 2007


tooru honda <tooru_honda at fast-mail.org> wrote:
   ...
>         def rand2():
>             while True:
>                 randata = urandom(2*1024)
>                 for i in xrange(0, 2*1024, 2):
>                     yield int(hexlify(randata[i:i+2]),16)    # integer
> in [0,65535]

another equivalent possibility, which might probably be faster:

import array
   ...
def rand2():
    while True:
        x = array.array("H")
        x.fromstring(urandom(2*4000))
        for i in x: yield i


Alex



More information about the Python-list mailing list