This repository was archived by the owner on Oct 5, 2022. It is now read-only.
This repository was archived by the owner on Oct 5, 2022. It is now read-only.
Uh-oh! Random number generator is not pseudorandom™ #130
Open
Description
$rand = $this->psl['crypt/rand'];
for ($i=0; $i<10000; $i++) {
$num = floor($rand->int(0, 1000000) / 1000);
if (isset($used[$num])) {
$used[$num]++;
}
else {
$used[$num] = 1;
}
}
ksort($used);
print_r($used);
Here is the output. As you can see it is pretty much a standard normal distribution curve right in the middle of the range:
Array
(
[479] => 1
[480] => 2
[481] => 1
[482] => 1
[483] => 4
[484] => 11
[485] => 26
[486] => 26
[487] => 63
[488] => 89
[489] => 162
[490] => 225
[491] => 345
[492] => 401
[493] => 509
[494] => 617
[495] => 770
[496] => 792
[497] => 853
[498] => 896
[499] => 830
[500] => 738
[501] => 675
[502] => 489
[503] => 411
[504] => 333
[505] => 253
[506] => 212
[507] => 91
[508] => 73
[509] => 51
[510] => 25
[511] => 12
[512] => 5
[513] => 6
[514] => 1
[518] => 1
)
Why not just use mt_rand()?