UUID Generator
Bulk-generate UUID v4 or sortable v7 identifiers using your browser's CSPRNG.
v4 is 122 random bits. Unpredictable, ideal for ids you expose in APIs and for anything security-sensitive.
v7 starts with a 48-bit millisecond timestamp, so values sort chronologically. Better for database primary keys: index locality, no random write amplification.
Both are generated with crypto.getRandomValues, never Math.random.
UUIDv7 output is monotonic within a millisecond only by timestamp — add a counter if you need strict ordering under high concurrency.
What a UUID actually is
A Universally Unique Identifier is a 128-bit value, conventionally written as 32 hex digits in five hyphen-separated groups: f47ac10b-58cc-4372-a567-0e02b2c3d479. The version digit and variant bits are embedded in fixed positions, which is why the third group always starts with 4 for v4 and 7 for v7.
"Universally unique" is probabilistic, not a guarantee: with 122 random bits, the chance of a collision across a billion ids per second for a century is still negligible. What matters practically is that ids can be generated independently, on any machine, without coordination.
v4 vs v7: the database argument
v4 is pure randomness. Its downside appears at scale: in a B-tree index, random keys land at random pages, so every insert dirties a different page. That causes write amplification, cache misses and index fragmentation — measurable slowdown once a table grows beyond memory.
v7 (standardized in RFC 9562, 2024) puts a 48-bit millisecond timestamp first. New rows sort near the end of the index, so inserts behave like an auto-increment integer, while the remaining 74 bits keep the value unique and non-guessable. If you are choosing a primary key format today, v7 is usually the better default. PostgreSQL 18 and several libraries now generate it natively.
Never use Math.random
Identifiers that appear in URLs, password-reset links and session tokens are security-relevant. Math.random() is a fast PRNG with a predictable internal state: observing a few outputs can let an attacker predict the next ones. Always use a CSPRNG — crypto.randomUUID() or crypto.getRandomValues() in the browser, crypto.randomUUID() in Node, secrets in Python.
Formatting variations
Hyphens are conventional but not part of the value. Braces come from the Windows GUID tradition, uppercase from older Microsoft APIs, and hyphen-free 32-character forms are common in URLs and compact storage. All four are the same 128 bits — pick one and stay consistent within a system.
Frequently asked questions
Are these UUIDs cryptographically random?
crypto.getRandomValues, the browser CSPRNG. Math.random is never used.