Skip to content

Category · 1 tool · 1 guide

UUID and random generators

Identifiers are everywhere in software: database primary keys, request IDs for tracing, idempotency keys for payment APIs, file names for uploads, correlation IDs in logs. Developers need them constantly, both in code and by hand when writing seed data, test fixtures or reproducing a bug.

UUIDs solve a specific problem: creating IDs that are unique without asking a central database for the next number. Different services, offline mobile clients and batch jobs can all mint IDs independently with a negligible chance of collision. The version matters, though. Random v4 UUIDs scatter inserts across a database index, while the newer time-ordered v7 keeps them roughly sequential and much friendlier to B-tree indexes.

The generators here use the browser's cryptographically secure random source, so the values are suitable for real use, not just placeholders. Nothing is generated or stored on a server.

Tools in this category

Common tasks

Key concepts

UUID
A 128-bit identifier written as 32 hex digits in five groups, such as 550e8400-e29b-41d4-a716-446655440000. The 13th hex digit shows the version.
UUID v4
Built from 122 random bits. Collisions are practically impossible, but the values have no order, so inserting them into an indexed column causes random page writes.
UUID v7
Defined in RFC 9562. It starts with a millisecond timestamp followed by random bits, so values sort by creation time while staying globally unique.
CSPRNG
A cryptographically secure pseudo-random number generator, such as crypto.getRandomValues in browsers. Math.random is not one and must not be used for IDs or tokens.
Idempotency key
A unique value a client sends with a request so the server can recognise a retry and return the original result instead of performing the action twice.

Best practices

  1. Prefer UUID v7 for new database primary keys; it keeps inserts sequential and still allows IDs to be generated anywhere.
  2. Store UUIDs in a native uuid or 16-byte binary column, not as 36-character strings, to halve storage and speed up indexes.
  3. Do not treat a UUID as a secret. v4 values are hard to guess, but use a dedicated random token for password resets and API keys.
  4. Generate IDs with a secure random source; never build them from Math.random or timestamps alone.
  5. Normalise case and format (lowercase, with hyphens) at your API boundary so the same ID is not stored two ways.

Guides