Re: Cryptographically random numbers

2006-03-07 Thread Gervasio Bernal
Tuvas wrote:
> from os import urandom
> def cstring(bytes):
> ret=''
> while(len(ret) 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.
> 
Thanks a lot, that is what I need.
If someone else have a more efficient way I will appreciate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cryptographically random numbers

2006-03-07 Thread Gervasio Bernal
Bryan Olson wrote:
> Tuvas wrote:
> 
>>Ahh, you are correct, that is a large bug... How about this one?
> 
> 
> Much better. Do note the comments from Emile van Sebille and Paul
> Rubin. There are some minor style and efficiency points, but it
> looks reasonable.
> 
> Incidentally, as of Python 2.4, the standard library offers
> random.SystemRandom, which will generate integers in any desired
> range using os.urandom as the entropy source.
> 
> 

How can I generate a random string containing digits, symbols and
letters? I will use this random string for the key of a cryptographic
algorithm.
Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list