UUID generator
The generator makes up to 100 random version 4 UUIDs at a time with your browser's crypto.randomUUID. Version 4 UUIDs don't sort by when they were made, so use version 7 if you need that. It runs in your browser; nothing you enter is uploaded.
How a version 4 UUID is built
A UUID is 128 bits, written as 32 hex digits in groups of 8, 4, 4, 4, and 12: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx. In
version 4, six of those bits are fixed. The first digit of the third group is always 4, for the version. The first digit of
the fourth group, shown as y, is always 8, 9, a, or b, which marks the
variant. The other 122 bits are random, and crypto.randomUUID takes them from the browser's secure random number generator.
RFC 9562 defines every UUID version. It came out in 2024 and replaced RFC 4122.
Can two UUIDs be the same?
Not by chance in any system you'll build. The birthday problem says you'd need about 2.7 × 1018 version 4 UUIDs before there's a 50% chance that any two of them match. At a billion UUIDs a second, you'd get there in about 86 years. If you do find a duplicate, suspect a weak random number generator or code that reused an ID.
Version 4 or version 7
Use version 7 for database primary keys. A version 7 UUID, also defined in RFC 9562, starts with a 48-bit Unix timestamp in milliseconds and fills most of the rest with random bits, so a later ID sorts after an earlier one. New version 7 keys go at the end of a B-tree index. Random version 4 keys land anywhere in it, so each insert can touch a different page of the index.
Use version 4 for IDs that other people or systems see, when the ID shouldn't reveal when it was made. Anyone can read the timestamp out of a version 7 UUID.
Uppercase or lowercase
RFC 9562 says to write UUIDs in lowercase and to compare them without regard to case. Some tools still print them in uppercase, including
uuidgen on macOS and the Windows registry editor. Tick Uppercase when the system you're pasting into expects
that form, and compare UUIDs case-insensitively in your own code.
Other ways to make a UUID
- Linux:
cat /proc/sys/kernel/random/uuidoruuidgen - JavaScript:
crypto.randomUUID(), in Node.js and in browsers on HTTPS pages andlocalhost - Python:
str(uuid.uuid4()) - PostgreSQL:
gen_random_uuid(), built in since version 13
Don't use a UUID as a secret
Password reset tokens and other secrets have to be hard to guess, and UUIDs don't promise that. RFC 9562 tells implementations not to assume UUIDs are hard to guess, and versions 1, 6, and 7 contain a timestamp anyone can estimate. Make tokens with your language's secure random function instead.