UUID 版本选择:随机、时间与命名空间
生成 v1、v4 或 v5 格式的 RFC 4122 UUID,支持批量生成、大写输出和自定义连字符格式。
c194b939-85f8-4c0c-88c3-5d83f7040d228ae84ee4-4cfd-4226-8243-b7a4a13723d4499583d8-385b-4200-99f1-e4fcd07d2d4677088f7e-f185-454c-9587-70fd4e1da1949daed7af-4f66-4074-b758-64b15bcf9dceUUID v4 示例
550e8400-e29b-41d4-a716-446655440000
格式:8-4-4-4-12 位十六进制
如何使用本工具
- 选择版本:最常用的是 v4(随机)。
- 用滑块设置数量(最多 50)。
- 若系统需要,可开大写或去掉连字符。
- 点击生成后,可单独复制或一键复制全部。
UUID 版本选择:随机、时间与命名空间
v4 随机;v1 需要时间/网卡信息(隐私场景需注意);v5 对命名空间+名称做哈希。无特殊需求多用 v4。
数据库仍应设唯一约束,极小碰撞概率不能替代事务校验。
What each option produces
- Version 4 (default): 122 random bits from your browser’s cryptographically secure generator, plus the fixed version and variant bits. This is the right choice for almost every new identifier.
- Version 1: built from the current time as the count of 100-nanosecond intervals since 15 October 1582 (the start of the Gregorian calendar), a random clock sequence, and a random 48-bit node ID with the multicast bit set. Classic v1 used the computer’s network MAC address as the node; the random node keeps your hardware address out of the ID, as RFC 9562 recommends.
- Nil UUID: all zeros (00000000-0000-0000-0000-000000000000), used as an explicit “no value” marker.
- Formatting: generate up to 50 at once, switch to uppercase, or remove the hyphens to get a 32-character hex string.
Reading a UUID
A UUID is 128 bits written as 32 hexadecimal digits in five groups (8-4-4-4-12):
f47ac10b-58cc-4372-a567-0e02b2c3d479
^ ^
| variant: 8, 9, a or b = RFC 9562 layout
version: 4 = randomThe first digit of the third group is always the version, and the first digit of the fourth group shows the variant. That is why a v4 UUID always has a 4 in the 13th position, and why only 122 of the 128 bits are random. For a v1 UUID the first three groups hold the timestamp, so anyone can read off when it was created — something to keep in mind before exposing v1 IDs publicly.
Which version should you use?
- v4 for general identifiers: API resource IDs, file names, idempotency keys, correlation IDs in logs.
- v7 for new database primary keys: defined in RFC 9562 (2024), it starts with a Unix-millisecond timestamp, so values sort in creation order and index far better than random v4 keys in B-tree indexes. This tool does not generate v7 yet; most languages have a maintained library for it.
- v1 when an existing system expects it, for example some older Cassandra schemas (TimeUUID).
- v5 when the same input must always produce the same ID (it hashes a namespace and a name with SHA-1). Not offered here because it needs those inputs.
Will two UUIDs ever collide?
For v4, the 50% collision point arrives at about 2.7 × 10¹⁸ generated IDs — roughly 86 years of producing a billion UUIDs every second. In practice, a duplicate is far more likely to come from a bug, such as a copied ID or a badly seeded generator in another system, than from chance. Keep a unique constraint on the database column anyway; it costs nothing and catches the bugs.
Unpredictable is not the same as secret. RFC 9562 advises against assuming UUIDs are hard to guess, so do not use one as a password-reset or session token — use a dedicated random token instead.
Storing and comparing UUIDs
- Use a native type where one exists — uuid in PostgreSQL, uniqueidentifier in SQL Server — or BINARY(16) in MySQL. Storing the 36-character string takes more than twice the space and slows indexes.
- Compare case-insensitively: f47ac10b… and F47AC10B… are the same UUID. Microsoft tools traditionally show GUIDs in uppercase, often wrapped in braces {…}.
- Hyphen-free 32-character strings are common in URLs and file names. Most parsers accept both forms, but be consistent within one system.
Generating UUIDs in code
When you need IDs at runtime rather than a handful to paste, every mainstream platform has a built-in v4 generator:
JavaScript crypto.randomUUID() // browsers (HTTPS) and Node.js Python import uuid; uuid.uuid4() Java java.util.UUID.randomUUID() C# / .NET Guid.NewGuid() PostgreSQL SELECT gen_random_uuid(); -- built in since v13 Go uuid.New() // github.com/google/uuid Shell uuidgen # macOS prints uppercase
In their current implementations these use the operating system’s secure random source, like this page does. Avoid hand-rolled versions built on Math.random(), which older code snippets online still copy around.
Related tools
These free tools pair well with this page — open them in a new tab to finish your workflow.
常见问题
什么是UUID?
UUID(通用唯一标识符)是一个128位数字,用于在计算机系统中唯一标识信息。它表示为32个十六进制数字,格式为8-4-4-4-12。
UUID各版本有什么区别?
UUID v1使用当前时间戳和MAC地址;UUID v4使用随机数,是最常用的版本。除非需要基于时间排序(v1)或基于名称的确定性(v3/v5),推荐使用v4。
UUID真的是唯一的吗?
UUID v4有122个随机位,可能的值约为2¹²²(约5.3×10³⁶)。在实际应用中,生成重复值的概率可以忽略不计。
可以将UUID用作数据库主键吗?
可以,UUID被广泛用作主键,特别是在分布式系统中,自增整数可能会冲突。注意随机UUID(v4)在某些数据库中可能导致索引碎片。
UUID区分大小写吗?
不区分。UUID表示不区分大小写,大写和小写十六进制数字均有效且等同。
在浏览器中生成UUID安全吗?
安全。此工具使用浏览器内置的crypto.randomUUID()或密码学安全的随机数生成器,输出适合生产使用。