<?PHP
$str
= uniqid(mt_rand(),1);
echo
‘sha1: ‘
,sha1(
$str
);
echo
‘<br>‘
;
echo
‘MD5: ‘
,md5(
$str
);
Using the Uniqid function, with the Mt_rand random function, the last hash is worth the final unique value.
But in the test, the uniqueness of the random number is found to have the same part, about 11 bits of the same (but no major obstacle)
Second method: GUID
<?PHP
echo
sprintf(
‘%04X%04X-%04X-%04X-%04X-%04X%04X%04X‘
, mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
echo
"<br>"
;
echo
sprintf(
‘%04X%04X-%04X-%04X-%04X-%04X%04X%04X‘
, mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
echo
"<br>"
;
echo
sprintf(
‘%04X%04X-%04X-%04X-%04X-%04X%04X%04X‘
, mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
echo
"<br>"
;
echo
sprintf(
‘%04X%04X-%04X-%04X-%04X-%04X%04X%04X‘
, mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
Method of generating random non-repeating strings using uniqid Mt_rand in PHP