您好,登錄后才能下訂單哦!
<?PHP
$str
= uniqid(mt_rand(),1);
echo
'sha1: '
,sha1(
$str
);
echo
'<br>'
;
echo
'MD5: '
,md5(
$str
);
采用uniqid函數(shù),配合mt_rand隨機(jī)函數(shù),最后使用散列值得出最終唯一值。
但是通過(guò)測(cè)試中,發(fā)現(xiàn)隨機(jī)數(shù)的唯一性有些相同部分,大概有11位相同的(但無(wú)大礙)
第二種方法: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));
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。