How to Generate a UUID: Online, Python, JavaScript, SQL & Excel
How to generate a UUID online or in Python, JavaScript, Java, PostgreSQL, Linux and Excel, plus UUID v4 vs v7 and what a Minecraft UUID really is.
To generate a UUID, open our UUID generator, set how many you need (1 to 1,000) and press Generate. You get random version 4 UUIDs like 3f2b8c1e-9a4d-4e7b-b1c2-5d6e7f8a9b0c, created by your browser's cryptographically secure crypto.randomUUID(). Tick Uppercase if your system wants capitals, then copy.
In code, it is usually one line: uuid.uuid4() in Python, crypto.randomUUID() in JavaScript, UUID.randomUUID() in Java and gen_random_uuid() in PostgreSQL. Details for each, plus Excel, Linux and Postman, are below.
What a UUID is
A UUID (universally unique identifier) is a 128-bit number written as 32 hexadecimal digits in five groups: 8-4-4-4-12. It lets different computers create IDs independently without checking a central counter and still not collide.
In 3f2b8c1e-9a4d-4e7b-b1c2-5d6e7f8a9b0c:
- The first digit of the third group (
4) is the version. - The first digit of the fourth group (
b) is the variant; for standard UUIDs it is always 8, 9, a or b.
UUID v4 vs v7
The current standard, RFC 9562 (published 2024), defines several versions. Two matter for most people:
| UUID v4 | UUID v7 | |
|---|---|---|
| Made from | 122 random bits | A millisecond Unix timestamp plus random bits |
| Sorts by creation time | No | Yes |
| Reveals when it was made | No | Yes, roughly |
| Good database primary key | Works, but random inserts can fragment indexes | Better: new rows go at the end of the index |
| Typical use | Tokens, file names, general IDs | Primary keys, event and log IDs |
Use v4 when you want an ID that gives nothing away. Use v7 for database keys where insert performance and natural ordering matter. Our generator makes v4 only; for v7, use your language or database as shown below.
Older versions exist too: v1 (time plus MAC address, which leaks the machine's identity), and v3/v5 (derived from a name by hashing, so the same input always gives the same UUID).
How to generate a UUID in Python
import uuid
str(uuid.uuid4()) # '9b1d...' random v4
uuid.uuid4().hex # same, without dashes
uuid.uuid7() # time-ordered v7, Python 3.14 and later
uuid.uuid5(uuid.NAMESPACE_URL, 'https://example.com') gives the same UUID every time for the same name.
How to generate a UUID in JavaScript
- Browsers and Node.js:
crypto.randomUUID()returns a v4 UUID string. In browsers it requires a secure context (HTTPS or localhost). - Without dashes:
crypto.randomUUID().replaceAll('-', '') - v7 in JavaScript: there is no built-in function yet; the popular
uuidpackage on npm providesv7()as well asv4().
Avoid hand-rolled generators built on Math.random(). They are not cryptographically secure and are more likely to collide.
How to generate a UUID in Java
UUID.randomUUID().toString() from java.util.UUID gives a v4 UUID. UUID.nameUUIDFromBytes(bytes) gives a name-based v3 UUID.
How to generate a UUID in PostgreSQL
SELECT gen_random_uuid();gives a v4 UUID. It is built in from PostgreSQL 13; older versions need thepgcryptoextension.SELECT uuidv7();gives a v7 UUID in PostgreSQL 18 and later.- As a column default:
id uuid PRIMARY KEY DEFAULT gen_random_uuid().
In MySQL, SELECT UUID(); returns a v1 UUID; in SQL Server, NEWID() returns a random GUID.
Generate a UUID in Linux, Mac and Windows
- Linux and Mac:
uuidgen(on Linux,uuidgen -rforces a random one). - Linux:
cat /proc/sys/kernel/random/uuid - Windows PowerShell:
New-Guidor[guid]::NewGuid()
How to generate a UUID in Postman
Use the built-in dynamic variables {{$guid}} or {{$randomUUID}} in a request body, header or URL. Postman fills in a fresh value every time the request is sent.
How to generate a UUID in Excel
Excel has no UUID function. This formula builds a string in v4 format:
=LOWER(DEC2HEX(RANDBETWEEN(0,4294967295),8)&"-"&DEC2HEX(RANDBETWEEN(0,65535),4)&"-4"&DEC2HEX(RANDBETWEEN(0,4095),3)&"-"&DEC2HEX(RANDBETWEEN(32768,49151),4)&"-"&DEC2HEX(RANDBETWEEN(0,16777215),6)&DEC2HEX(RANDBETWEEN(0,16777215),6))
Two cautions:
RANDBETWEENrecalculates every time the sheet changes, so the IDs keep changing. Copy the cells and use Paste Special > Values to freeze them.- Excel's random numbers are not cryptographically secure. Fine for test data; for real IDs, generate them with our UUID generator (up to 1,000 at once) and paste them into the sheet.
What is a Minecraft UUID?
In Minecraft Java Edition, every player account has a UUID assigned by Mojang, used by servers to track players even after a name change. You cannot generate your UUID; you look it up from your username (many server tools and community sites do this). Offline-mode servers instead derive a name-based UUID from the player's name. A random UUID generator, including ours, gives new random IDs, which are useful for things like data packs or custom entities, but it will not give you a player's UUID.
Are UUIDs secure?
A v4 UUID from crypto.randomUUID() is unpredictable, so it can work as a hard-to-guess identifier, for example in an unlisted share link. But it was designed to be unique, not to be a secret:
- v1 and v7 UUIDs contain timestamps and are partly predictable.
- UUIDs often end up in logs and URLs.
For passwords, use the password generator. For API keys or tokens, use a dedicated random token of at least 128 bits. If you need a fingerprint of data rather than a random ID, use a hash such as SHA-256 with the SHA-256 hash generator; see our guide on checking a file's SHA-256 hash.
Common mistakes
- Using
Math.random()or a home-made function instead of a real UUID generator. - Storing UUIDs as text in a database that has a native
uuidtype. The native type is smaller and faster. - Using random v4 UUIDs as the clustered primary key on very large, insert-heavy tables, where v7 would perform better.
- Assuming case matters. UUIDs are case-insensitive;
ABC...andabc...are the same ID, though lowercase is the usual convention. - Forgetting to freeze Excel formulas, so the IDs change on every edit.
Questions
What is the difference between UUID v4 and v7?
A v4 UUID is fully random. A v7 UUID starts with a timestamp, so UUIDs created later sort after earlier ones. That makes v7 friendlier as a database primary key, while v4 reveals nothing about when it was created.
Can two UUIDs ever be the same?
In theory yes, in practice no. A v4 UUID has 122 random bits, so the chance of a duplicate is negligible for any realistic number of IDs, as long as a proper random generator is used.
Is a GUID the same as a UUID?
Yes. GUID is Microsoft's name for the same 128-bit identifier. Both use the same 8-4-4-4-12 hexadecimal format.
How do I generate a UUID without dashes?
Generate a normal UUID and remove the hyphens. In Python use uuid.uuid4().hex; in JavaScript use crypto.randomUUID().replaceAll('-', ''). From our generator, paste the list into any editor and replace '-' with nothing.
Can I generate a UUID in Excel?
Excel has no UUID function, but a formula built from RANDBETWEEN and DEC2HEX can produce v4-format UUIDs. It is fine for test data; for anything important, use a real generator.