UUID Generator (v1, v4, v5)

Generate UUID

Generated UUID

Your generated UUID will appear here.

About UUID Versions

UUIDs (Universally Unique Identifiers) are used to uniquely identify information in a distributed system. Different UUID versions offer various methods for generating these identifiers based on time, randomness, or a name-based hashing scheme.

UUID Version 1 (v1) – Time-based UUID

A v1 UUID is generated using the current timestamp (time-based) and the machine’s network address (usually the MAC address). This ensures that the generated UUID is unique across both time and space.

How v1 Works:
  • A timestamp is taken down to 100-nanosecond precision.
  • The timestamp is then combined with a machine identifier (typically the MAC address).
  • The result is a UUID that is guaranteed to be unique in time and space.
UUID Version 4 (v4) – Random UUID

A v4 UUID is generated using random values. It is the most widely used UUID version because it offers a very high likelihood of uniqueness without requiring a timestamp or machine address.

How v4 Works:
  • 122 random bits are generated, and 6 fixed bits are used for versioning and variant.
  • The result is a UUID with no relation to time or location, but it has a high level of randomness, making collisions unlikely.
UUID Version 5 (v5) – Name-based UUID

A v5 UUID is generated by hashing a namespace and a name. It is used to generate unique identifiers based on specific names, which ensures that the same name in the same namespace will always generate the same UUID.

How v5 Works:
  • A name (e.g., a URL, domain name, or any string) and a namespace (typically a UUID) are passed through a hashing algorithm (SHA-1).
  • The result is a deterministic UUID, meaning that given the same input, the output will always be the same UUID.

When to Use Each UUID Version

  • v1 (Time-based): When you need a unique identifier that includes a timestamp, useful for systems that need to track when an ID was created.
  • v4 (Random): For most cases where you just need a unique identifier, and don't need to embed any time or machine-specific information.
  • v5 (Name-based): When you need to generate a consistent UUID based on a name or a namespace, for example, associating a specific UUID with a domain name, file, or string.

How to Use UUID Generator in JavaScript:

To generate UUIDs in JavaScript, you can use the uuid library to generate UUIDs. Below are examples of how to generate UUID v1, v4, and v5 using JavaScript.

Step 1: Install the uuid library

You can include the uuid library in your project via CDN for web projects, or install it via npm for Node.js:

  • CDN:
    <script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.3.2/uuid.min.js"></script>
  • npm:
    npm install uuid
Step 2: Generate UUIDs using JavaScript
// Importing uuid (if using Node.js, or use the CDN version for browsers)
const { v1, v4, v5 } = uuid;

// Generate a Time-based (v1) UUID
const v1UUID = v1();
console.log("v1 UUID:", v1UUID);

// Generate a Random-based (v4) UUID
const v4UUID = v4();
console.log("v4 UUID:", v4UUID);

// Generate a Name-based (v5) UUID (using DNS namespace)
const v5UUID = v5("example.com", v5.DNS);
console.log("v5 UUID:", v5UUID);