Back to blog

UUID v4 Generator: How Random UUIDs Work and When to Use Them

What is a UUID v4 generator?

A UUID v4 generator creates random Universally Unique Identifiers in the standard format:

xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx

The 4 identifies the version. The y position identifies the RFC variant. The remaining bits are generated randomly, giving UUID v4 a very large space of possible values.

Use the DevToolkit UUID Generator to create one value or a bulk list locally in your browser. The tool supports UUID v4 and v7, copying, formatting, and exports.

Generate a UUID v4 in JavaScript

Modern browsers and Node.js provide a cryptographically strong built-in option:

const id = crypto.randomUUID();
console.log(id);

For older runtimes, use a maintained UUID library rather than writing a random-number implementation yourself. A secure random source matters more than the formatting step.

Generate a UUID v4 in Python

import uuid

identifier = uuid.uuid4()
print(identifier)

The returned value uses the familiar 36-character representation with hyphens.

When should you use UUID v4?

UUID v4 works well for database identifiers, upload names, correlation IDs, and client-generated records when independent systems need to create IDs without coordinating with a central sequence.

Use another design when database locality, compactness, or human readability matters more. UUID v7 can be a better fit when values should generally sort by creation time. See what a UUID is and UUID v4 versus UUID v1 for a broader comparison.

UUID v4 is not authorization

Random-looking identifiers are not automatically permissions. If an API exposes a UUID in a URL, it must still authenticate the caller and authorize access to that record. Do not use UUIDs as passwords or as the only protection for private resources.

Validate a generated UUID

To check the standard UUID v4 shape, use the following pattern:

^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$

This checks format, version, and variant. It does not prove uniqueness or secure generation. Test it in the Regex Tester.

Summary

UUID v4 is a practical random identifier for distributed applications. Generate it with a cryptographically secure API, enforce uniqueness in the database, and keep authorization separate from identifier generation.