Cryptographically random numbers

Bryan Olson fakeaddress at nowhere.org
Mon Mar 6 09:33:33 EST 2006


Tuvas wrote:
> Okay, I'm working on devoloping a simple, cryptographically secure
> number, from a range of numbers (As one might do for finding large
> numbers, to test if they are prime). My function looks like this:
> 
> def cran_rand(min,max):
>     if(min>max):
>         x=max
>         max=min
>         min=x
>     range=round(log(max-min)/log(256))
>     if range==0:
>         range=1
>     num=max+1
>     while(num>max):
>         num=min+s2num(urandom(range))
>     return num
> 
> Any comments on this? I think it should hold up to a test, it seems to
> work alright.

Have to disagree. Try:

   for _ in range(100):
       print cran_rand(0, 500)

How many numbers greater than 255 do you get?


I have more comments, but that's the biggest issue.


-- 
--Bryan



More information about the Python-list mailing list