Generate UUID v4, ULID, or NanoID identifiers using cryptographically secure randomness from the Web Crypto API. Three formats because they solve different problems.
Generate cryptographically secure unique identifiers. UUIDv4, ULID (time-sortable), or NanoID (URL-safe, compact).
The choice matters more than it looks. UUID v4 is 128 bits of pure randomness: universally supported, and terrible as a primary key in a B-tree index because inserts land in random pages and fragment the index. ULID keeps the same 128 bits but leads with a 48-bit timestamp, so identifiers sort chronologically and insert sequentially, which is dramatically kinder to Postgres and MySQL indexes.
NanoID is the compact option: 21 characters against UUID's 36, URL-safe, with collision odds comparable to UUID v4 at realistic volumes. Reach for it when the identifier is going in a URL and length is user-visible.