Cryptographically random numbers

Tuvas tuvas21 at gmail.com
Tue Mar 7 09:20:18 EST 2006


from os import urandom
def cstring(bytes):
    ret=''
    while(len(ret)<bytes):
        c=os.urandom(1)
        if c>'0' and c<'z':
            ret=ret+c
    return ret

That should do it, though I bet there might be a more efficient way. I
don't know if that's the set of characters you want to use, but... If
you want a better answer, you'd have to be more specific.




More information about the Python-list mailing list