
Chun-Sheng, Li - 2020-07-09 06:29:34
According to GUID generating, it is possible to cause collision GUID generating.
To prevent collision, I think it should let some random numbers not be constraint numbric range.
And it should use the now timestamp to be dynamic numeric ranges.
For example, please consider following code snippets about generating GUID:
<?php
//......
$now = time();
$guid = sprintf(
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand($now, $now + 20479),
mt_rand($now + 20479 + 1, $now + 20479 + 1 + 49151),
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(0, 65535)
);
//......