<?php
$gens = [];
for ($i = 0; $i < 1000; $i++) {
$entropy=1;
if (function_exists("posix_getpid"))
$entropy *= posix_getpid();
if (function_exists("memory_get_usage"))
$entropy *= memory_get_usage();
list($usec, $sec) = explode(" ", microtime());
$usec *= 1000000;
$entropy *= $usec;
mt_srand($entropy);
$result = mt_rand();
if (in_array($result, $gens)) {
echo 'Count: ' . count($gens) . PHP_EOL;
echo 'COLLISION: ' . $result . PHP_EOL;
} else {
$gens[] = $result;
}
}
- Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.24, 7.0.26 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
- Output for 7.0.25
- Count: 933
COLLISION: 691473865
preferences:
168.33 ms | 401 KiB | 195 Q