QCSunny Lab

UUID / ULID / NanoID GeneratorUUID / ULID / NanoID 生成器

Generate UUID v4 (cryptographically random) and modern UUID v7 (timestamp-ordered, RFC 9562) identifiers in bulk — up to 100 at a time — with custom uppercase and hyphen formatting.

UUID v4 provides 122 bits of pure randomness, ideal for secure stateless tokens. UUID v7 combines a 48-bit millisecond Unix timestamp with 74 random bits, giving monotonic time ordering that drastically improves database B-tree index performance and cache locality.

Frequently asked questions

What is the difference between UUID v4 and UUID v7?

UUID v4 is completely random. UUID v7 encodes a 48-bit millisecond timestamp in the prefix, so UUIDs sort chronologically by creation time.

Why use UUID v7 for database primary keys?

Pure random UUIDs cause page fragmentation in B-trees (random disk writes). UUID v7 is sequential, meaning new inserts append near the end of index leaves, boosting throughput.

Can two generated UUIDs collide?

The chance is astronomically small — you would need billions generated per millisecond to observe collisions.

中文说明

批量生成随机 UUID v4 以及现代时间有序的 UUID v7(RFC 9562 标准),支持自定义大小写与连字符格式,单次最高可生成 100 个。

UUID v4 提供 122 位纯密码学随机性,适合无状态安全令牌;UUID v7 将 48 位 Unix 毫秒时间戳与 74 位随机数结合,具有天然的时间单调递增性,可大幅提升 PostgreSQL、MySQL 等数据库的 B 树索引性能与写入局部性。

常见问题

UUID v4 和 UUID v7 有什么区别?

UUID v4 完全随机;UUID v7 前缀包含 48 位毫秒时间戳,生成的 ID 天然按创建时间排序。

为什么数据库主键推荐 UUID v7?

纯随机的 UUID v4 会导致 B+ 树索引严重碎片化;UUID v7 具有时间局部性,新记录追加在索引末尾,显著降低 I/O 压力。

两个 UUID 可能发生碰撞重复吗?

概率微乎其微——即使在同一毫秒内也拥有 74 位的随机熵,需要每毫秒生成数十亿个才可能碰撞。