Last updated October 26, 2026
UUID Generator
UUID Generator
All generation happens in this browser; nothing is sent to a server.
What is a UUID
A UUID (universally unique identifier) is a 128-bit label, usually written as five groups of hex digits such as 550e8400-e29b-41d4-a716-446655440000. The point is uniqueness without a central registry: two independently generated UUIDs are effectively never equal, which is why they appear in databases, API keys and distributed systems. A version 4 UUID keeps 122 random bits, and the remaining bits mark the version and variant.
UUID v4 vs v7
v4 UUIDs are fully random, so their lexicographic order carries no meaning. v7 UUIDs (RFC 9562) put a 48-bit millisecond timestamp first, then random bits: two v7 values generated close in time sort near each other. That ordering makes v7 convenient for database primary keys and time-sequenced event IDs, while v4 remains the default everywhere a purely random identifier is fine.
Generate a UUID in Python
Python's uuid module ships with the generator: import uuid then uuid.uuid4() returns a random v4 object, and str(uuid.uuid4()) gives the dashed form you normally store. For a v7-style value you can build one from the module constants, but most projects simply call uuid4() unless they need time ordering.
Generate a UUID in JavaScript
Modern browsers expose crypto.randomUUID(), which returns a v4 UUID string directly: crypto.randomUUID(). If you need v7, construct the 48-bit timestamp prefix yourself and append random bits, or use a small library that implements RFC 9562. Node.js also ships crypto.randomUUID() in the crypto module.
Generate a UUID in PostgreSQL
PostgreSQL has gen_random_uuid() built in, returning a random v4 UUID per row. For time-ordered identifiers you can enable the uuidv7() function from the pgcrypto extension in newer releases, or store a v7 generated by the application. The uuid column type accepts either, and both index cleanly.
Generate a UUID in Java
Java's java.util.UUID.randomUUID() returns a v4 UUID, and its toString() produces the standard dashed form. There is no built-in v7 factory in the core API; projects that want time-ordered keys use a small helper or library implementing RFC 9562.
UUID vs GUID
GUID is the name Microsoft uses for the same 128-bit identifier idea. The terms are interchangeable in practice: a GUID is a UUID implementation, and a UUID can be stored wherever a GUID is expected. The generation rules, version bits and string format line up, so tooling rarely needs to tell them apart.
Frequently asked questions
Can two generated UUIDs ever collide?
The probability is negligible rather than zero. A v4 UUID has 122 random bits, so around 2^122 distinct values exist; generating billions of IDs still leaves collision odds far below everyday risks. If your system truly cannot tolerate any repeat, store the value and check on insert, or add a unique constraint and retry.
Is it safe to expose a UUID publicly?
A random v4 UUID is not a secret and exposes no personal data by itself: it is just 128 bits with no user information baked in. Keep real authentication tokens out of URLs regardless, and never rely on a v7 timestamp to hide when a record was created if timing matters to your users.
Why is v7 better for database primary keys?
v7 values begin with a millisecond timestamp, so rows inserted close together share a similar prefix and sort into nearby index pages. That keeps B-tree inserts local instead of scattering writes across the table, which usually reduces page splits and index churn compared with fully random v4 keys.