UUID generator
Generate random v4 UUIDs or time-ordered v7 UUIDs in bulk, from your browser. Explains which version to use as a database primary key, and why.
Runs in your browser
v4 or v7
A v4 UUID is 122 random bits. A v7 UUID replaces the leading 48 bits with a Unix millisecond timestamp and fills the rest with randomness. Both are 128 bits, both are written as 36 characters, and both are unique in any practical sense. The difference is ordering.
v4 9f8b3c12-5d4e-4a7b-8c19-2f6e0a5b7d31
v7 0198c4a1-7e2f-7c33-b8d0-5a1c9e7f2b64
└── milliseconds since 1970 ──┘
Sort a list of v7 UUIDs as strings and they come out in creation order. Sort v4 UUIDs and you get noise.
Why that matters for a database
Most relational databases store a table in a B-tree keyed on the primary key. Inserting in random order means every insert lands in a different page: the working set becomes the whole index rather than its tail, page splits multiply, and write throughput falls as the table grows. Inserting in roughly ascending order appends to one hot page instead.
This is the reason MySQL guidance has long warned against random UUID primary keys, and the reason v7 was standardised — it landed in RFC 9562 in May 2024, alongside v6 and v8, superseding RFC 4122.
Choose v7 for anything you will insert into an indexed column, and for records where a rough creation time being visible is acceptable. Choose v4 when the identifier is public-facing and must leak nothing at all: a v7 value tells anyone holding it when the record was made, to the millisecond.
Reading the version and variant
Two positions are fixed by the specification and are not random:
- The 13th hex digit is the version:
4or7above. - The 17th hex digit is the variant: one of
8,9,aorb.
So a v4 UUID has only 122 free bits, not 128. That is still enough that collisions are not a practical concern — you would need on the order of a billion UUIDs per second for decades before a duplicate became likely.
Generating them in code
crypto.randomUUID() // v4, browser and Node 19+
SELECT gen_random_uuid(); -- PostgreSQL 13+, v4
import uuid; uuid.uuid4()
v7 has no built-in in most standard libraries yet; PostgreSQL added uuidv7() in version
18. Until then it comes from a library, or from a few lines that write the timestamp into
the first six bytes yourself.
Your data stays here
Values are generated in your browser with crypto.getRandomValues, the platform’s
cryptographically secure random source. Nothing is generated on a server and nothing is
logged, so a UUID you take from this page has been seen only by your own machine.