I've been testing the randomness of generated values in PHP, and have been considering 32bit hexadecimal to represent a unique state within a given time frame.
I wrote this simple test script:
$checks = [];
$i = 0;
while (true) {
    $hash = hash('crc32b', openssl_random_pseudo_bytes(4));
    echo $hash . PHP_EOL;
    if (in_array($hash, $checks)) {
        echo 'Copy: ' . $i . PHP_EOL;
        break;
    }
    $i++;
    $checks[] = $hash;
}
Surprisingly (to me) this script generates a copy in less than 100,000 iterations, and as low as 1000 iterations.
My question is, am I doing something wrong here? Out of 4 billion possibilities, this level of frequency seems too unlikely.
 
     
    