Nanoid & CUID Generator
NewGenerate URL-safe unique IDs in nanoid or CUID2-style format, with configurable length and batch count.
—
IDs are generated with crypto.getRandomValues in your browser — nothing is sent to a server. Nanoid uses the standard URL-safe alphabet; the CUID2-style output mimics cuid2's lowercase alphanumeric, collision-resistant look but is not the canonical cuid2 algorithm (which also mixes in a fingerprint and counter).
Frequently Asked Questions
How is randomness generated?
Every ID uses the browser's Web Crypto API (crypto.getRandomValues), which is a cryptographically secure pseudorandom number generator — the same underlying source real nanoid and cuid2 libraries use, not Math.random().
Is the CUID2-style output identical to the real cuid2 algorithm?
No — real cuid2 also mixes in a monotonic counter, a per-session fingerprint, and a hash pass to strengthen collision resistance across distributed systems. This tool reproduces cuid2's visual style (lowercase alphanumeric, always starting with a letter) using pure random generation, which is fine for prototyping but isn't a drop-in replacement for the npm cuid2 package in production code.
Why does nanoid use a different character set than UUIDs?
Nanoid's default alphabet (A-Za-z0-9_-) is chosen to be URL-safe without escaping, and at 21 characters it has a comparable collision probability to a standard 36-character UUID while being noticeably shorter.
What length should I use?
Nanoid's default of 21 characters is a common default that balances brevity with an extremely low collision probability for most applications generating fewer than trillions of IDs. Shorter IDs (8-12 chars) are fine for low-volume use like short URLs, but raise collision risk faster as volume grows.
Are these IDs suitable as database primary keys?
Yes, functionally — they're just random strings — but consider that unlike auto-incrementing integers or ULIDs, nanoid/cuid-style IDs are not sortable by creation time, which matters if your queries rely on ID order.