UUID generator
Generate one UUID or a few thousand, using the browser's cryptographically secure random source rather than Math.random. Nothing is sent anywhere.
Runs in your browser — nothing is uploadedWhich version
v4 is random and the right default. v7 is newer and time-ordered, which makes it far better as a database primary key because inserts stay sequential instead of scattering across the index. v1 embeds a timestamp and MAC address, so it leaks information and is best avoided.
Collisions
A v4 UUID has 122 random bits. You would need to generate billions per second for a century
before a collision became likely, so for practical purposes they do not collide, provided the randomness is
real. UUIDs built from Math.random() do collide, and that is a genuine production bug.
Reserved values
The nil UUID 00000000-0000-0000-0000-000000000000 and the max UUID
ffffffff-ffff-ffff-ffff-ffffffffffff are both defined by the spec and make good sentinels in
tests.
Questions
Are these UUIDs cryptographically secure?
Yes. They come from the browser's crypto random source, not Math.random, which is what makes the collision maths hold.
Should I use a UUID as a database primary key?
A random v4 scatters inserts across the index and hurts write performance at scale. A time-ordered v7, or a separate sequential key with the UUID as an external identifier, avoids that.
Can two UUIDs be the same?
In theory yes, in practice no for v4 with a real random source. Collisions in the wild are almost always a weak generator rather than bad luck.
Is there a UUID safe for test data?
The nil and max UUIDs are both reserved by the specification and are unambiguous as test sentinels.