Answer the question
In order to leave comments, you need to log in
How to check the unique value generator for the probability of a collision?
There are a dozen ways to generate a string, I understand that you can put a string to generate until there is a collision, but it can be tens of millions of records.
function randomString(int $length = 16): string {
$string = '';
while (($len = \strlen($string)) < $length) {
$size = $length - $len;
$bytes = \random_bytes($size);
$string .= \substr(
\str_replace(['/', '+', '='], '', \base64_encode(sprintf('%s%s', $bytes, time()))),
0,
$size
);
}
return $string;
}
$isCollisioned = false;
$generated = [];
while (false === $isCollisioned) {
$str = randomString(64);
if (true === in_array($str, $generated, true)) {
var_dump(count($generated));
}
$generated[] = $str;
}
Answer the question
In order to leave comments, you need to log in
Just take a virtual one anywhere and run it. What is the problem? You can also take more powerfully so that it is processed faster. You can run in multiple threads with different ranges
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question