Collision for generating GUID

Recommend this page to a friend!

      PHP GUID Generator  >  All threads  >  Collision for generating GUID  >  (Un) Subscribe thread alerts  
Subject:Collision for generating GUID
Summary:It's possible to generate GUID
Messages:1
Author:Chun-Sheng, Li
Date:2020-07-09 06:29:34
 

  1. Collision for generating GUID   Reply   Report abuse  
Picture of Chun-Sheng, Li 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)
);
//......

 

For more information send a message to info at phpclasses dot org.