Hello,
I've got two random number/statistics questions I'd like you to
review. My first question is not directly related to PHP, but will be
implemented in PHP, as explained in my second question, so let's go:
I want to generate 10000 strings of x characters, with one chance (or
less) on a million that you can guess them by just randomly typing
them. So I need to know what is the value of x.
I wrote the following equation :
36^x/10000 = 1000000
<=> 36^x = 10000 * 1000000
<=> 36^x = 1010
<=> x = ln(1010)/ln(36)
<=> x = 23.025850929940 456840179914546 844/3.5835189384561 100016249547167 614
<=> x = 6.4254860446923 437997173954827 712
So, a 7-characters string would be good enough.
So my first question is: is my reasoning OK? Knowing my math
abilities, I doubt it very much! ;)
The second question I have is related to PHP's rand() function. I've
read many times that rand() is not random enough, especially when
generating long lists of this kind. Would you use something that's
more powerful than rand(), are there stronger random functions, within
PEAR for instance, or anything?
Thanks,
JFLac
I've got two random number/statistics questions I'd like you to
review. My first question is not directly related to PHP, but will be
implemented in PHP, as explained in my second question, so let's go:
I want to generate 10000 strings of x characters, with one chance (or
less) on a million that you can guess them by just randomly typing
them. So I need to know what is the value of x.
I wrote the following equation :
36^x/10000 = 1000000
<=> 36^x = 10000 * 1000000
<=> 36^x = 1010
<=> x = ln(1010)/ln(36)
<=> x = 23.025850929940 456840179914546 844/3.5835189384561 100016249547167 614
<=> x = 6.4254860446923 437997173954827 712
So, a 7-characters string would be good enough.
So my first question is: is my reasoning OK? Knowing my math
abilities, I doubt it very much! ;)
The second question I have is related to PHP's rand() function. I've
read many times that rand() is not random enough, especially when
generating long lists of this kind. Would you use something that's
more powerful than rand(), are there stronger random functions, within
PEAR for instance, or anything?
Thanks,
JFLac
Comment