优化uuid生成

pull/497/head
Karson 2025-06-30 11:24:37 +08:00
parent ea8ea715b9
commit d1dfff490b
1 changed files with 5 additions and 6 deletions

View File

@ -100,20 +100,19 @@ class Random
/**
* 获取全球唯一标识
* @param string $tag 标识
* @return string
*/
public static function uuid(): string
public static function uuid($tag = ''): string
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
'%04x%04x-%04x-%04x-%04x-%12s',
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff)
substr(bin2hex(random_bytes(8)), 0, 6) . substr(md5(uniqid($tag ?: mt_rand(), true)), 0, 6)
);
}
}