PHPでUUID、その2です。何をやってるのか、よくわかっていませんが、見事にUUIDのバージョン4が生成されます。素晴らしいです。
参考サイト
uniqid(PHP Manual)
uuid — RFC 4122に準拠したUUID オブジェクト(Python ドキュメント)
<?php
function v4() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// time_low UUIDの最初の32ビット
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// time_mid UUIDの次の16ビット
mt_rand(0, 0xffff),
// time_hi_version UUIDの次の16 ビット
mt_rand(0, 0x0fff) | 0x4000,
// clock_seq_hi_variant UUIDの次の8ビット
// clock_seq_low UUIDの次の8ビット
mt_rand(0, 0x3fff) | 0x8000,
// node UUIDの最後の48ビット
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
$uuid4 = v4() ;
echo $uuid4 ;
?>
参考サイト
uniqid(PHP Manual)
uuid — RFC 4122に準拠したUUID オブジェクト(Python ドキュメント)