UUID 生成器 使用教程
详细使用指南、最佳实践与常见问题解答
使用场景
UUID/ULID 生成器适用于数据库主键生成、分布式系统 ID 分配、测试数据填充、会话 Token 生成等场景。当你需要在没有中心化 ID 分配服务的情况下生成全局唯一标识符,或者需要按时间排序的 ID 用于日志、事件流时,这个工具能快速帮你完成。
Use Cases
The UUID/ULID generator is useful for database primary keys, distributed system IDs, test data seeding, and session tokens. Use it when you need globally unique identifiers without a centralized ID service, or time-ordered IDs for logs and event streams.
功能特点
- 三种格式:UUID v4(纯随机)、UUID v7(时间排序)、ULID(26 字符字典序友好)
- 批量生成:一次最多生成 50 个 ID
- 格式控制:可切换大小写、是否带连字符
- 密码学安全:使用 crypto.getRandomValues 真随机源
- 完全本地生成:不上传服务器,可用于生产环境
Features
- Three formats: UUID v4 (random), UUID v7 (time-ordered), ULID (26-char lexicographically sortable)
- Batch generation: up to 50 IDs at once
- Format control: toggle uppercase and hyphens
- Cryptographically secure: uses crypto.getRandomValues true random source
- Fully local: never uploaded, safe for production use
使用示例
示例 1:场景一:为数据库插入测试数据时需要 100 个主键,将数量滑到 50,连续点击两次生成,复制全部到 SQL 文件中。
示例 2:场景二:调试分布式系统需要可排序的事件 ID,选择 UUID v7,生成后按字符串排序即为时间顺序。
示例 3:场景三:前端生成临时会话 ID,选择 ULID(更短、URL 友好),关闭连字符选项,得到 26 字符纯字符串。
Examples
Example 1: Scenario 1: Need 100 primary keys for database test data? Slide count to 50, click Generate twice, copy all to your SQL file.
Example 2: Scenario 2: Debugging a distributed system needs sortable event IDs — pick UUID v7; sorting the strings gives time order.
Example 3: Scenario 3: Frontend needs a temporary session ID — pick ULID (shorter, URL-safe), disable hyphens to get a 26-char string.
最佳实践
- 生产环境优先用 UUID v7 或 ULID,便于按时间排序与索引
- 需要 URL 友好时选 ULID(无连字符、26 字符、大小写不敏感)
- 不要用 UUID v4 作为数据库主键(无序导致 B-tree 索引碎片化)
- 涉及安全场景(如 Token)务必用本工具的 crypto.getRandomValues,不要用 Math.random
Best Practices
- Prefer UUID v7 or ULID in production for time-ordered, index-friendly keys
- Use ULID for URL-friendly IDs (no hyphens, 26 chars, case-insensitive)
- Avoid UUID v4 as a database primary key (random order causes B-tree fragmentation)
- For security-sensitive tokens, use this tool's crypto.getRandomValues, never Math.random
常见问题
UUID v4 和 v7 有什么区别?
v4 是纯随机的,无任何顺序信息;v7 前 48 位是毫秒时间戳,因此按字符串排序就是按生成时间排序,适合数据库索引。
ULID 比 UUID 好在哪里?
ULID 是 26 字符的 Crockford Base32 编码,比 UUID(36 字符)短 10 个字符;大小写不敏感;字典序排序即为时间序;URL 友好无特殊字符。
生成的 ID 真的安全吗?
是。本工具使用 Web Crypto API 的 crypto.getRandomValues,是浏览器提供的密码学安全随机数源,与 crypto.randomUUID 同源。
可以一次生成多个 ID 吗?
可以。拖动"生成数量"滑块,最多一次生成 50 个。生成后可点击"复制全部"一次性复制到剪贴板。
FAQ
What is the difference between UUID v4 and v7?
v4 is fully random with no ordering. v7 embeds a 48-bit millisecond timestamp in the first bits, so string sorting equals time sorting — ideal for database indexes.
Why is ULID better than UUID?
ULID is 26 chars of Crockford Base32 — 10 chars shorter than UUID (36 chars), case-insensitive, lexicographically sortable by time, and URL-safe with no special characters.
Are the generated IDs cryptographically secure?
Yes. This tool uses the Web Crypto API's crypto.getRandomValues, the same cryptographically secure source behind crypto.randomUUID.
Can I generate multiple IDs at once?
Yes. Drag the Count slider up to 50. After generation, click "Copy All" to copy them all to the clipboard.