Generate Random UUID

Click the button or press space to generate a new UUID. Click the UUID to copy it.

UUID copied to clipboard!

What is a UUID?

A UUID (Universally Unique Identifier), also known as GUID (Globally Unique Identifier), is a 128-bit number used to uniquely identify information in computer systems. UUIDs are standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE).

Each UUID consists of 32 hexadecimal digits displayed in 5 groups separated by hyphens, in the format: 8-4-4-4-12 characters (for example: 550e8400-e29b-41d4-a716-446655440000).

Why Use UUIDs?

Uniqueness

UUIDs are designed to be practically unique across space and time. The probability of generating two identical UUIDs is so low that it can be safely ignored in most applications.

Decentralization

UUIDs can be generated independently without central coordination, making them perfect for distributed systems and microservices architectures.

Privacy

Unlike sequential IDs, UUIDs don't reveal information about the order or number of items in your system, providing better security and privacy.

Scalability

Perfect for large-scale systems where multiple servers need to generate unique identifiers without coordination.

Common Use Cases

  • Database primary keys and foreign keys
  • Distributed systems and microservices
  • Session IDs and transaction IDs
  • File and document identifiers
  • Cross-database record linking

UUID Versions

There are several versions of UUID, each generated differently:

  • Version 1 (Time-based): Uses the current timestamp and the MAC address of the computer.
  • Version 3 (MD5 hash-based): Generated by hashing a namespace identifier and name.
  • Version 4 (Random): Generated using random or pseudo-random numbers. This is the most commonly used version and what our generator creates.
  • Version 5 (SHA-1 hash-based): Similar to Version 3, but uses SHA-1 hashing.

Our generator uses Version 4 (Random) UUIDs, which provide the best balance of uniqueness and security for most applications.

Technical Implementation

Our UUID generator uses the Web Crypto API's crypto.getRandomValues() to ensure cryptographically secure random numbers. This provides better randomness than traditional pseudo-random number generators.

Frequently Asked Questions

What is a random UUID?

A random UUID (Version 4) is a 128-bit identifier that uses random or pseudo-random numbers to create a unique string. It consists of 32 hexadecimal digits arranged in 5 groups separated by hyphens (8-4-4-4-12 format). Random UUIDs are commonly used in distributed systems, databases, and web applications to generate unique identifiers without central coordination.

What does crypto.randomUUID() do?

The crypto.randomUUID() method is a Web API function that generates a Version 4 UUID using cryptographically strong random values. It uses the device's cryptographic random number generator to ensure high-quality randomness, making it more secure than traditional random number generators. The function returns a string containing a 36-character UUID (32 alphanumeric characters plus 4 hyphens).

What is a UUID example?

A typical UUID looks like this: 550e8400-e29b-41d4-a716-446655440000. The format always follows the pattern xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where x represents a hexadecimal digit (0-9 or a-f). This standardized format ensures consistency across all systems and applications that use UUIDs.

Is a UUID always 36 characters?

Yes, a UUID in its standard string representation is always 36 characters long. This consists of 32 hexadecimal digits plus 4 hyphens that separate the five groups. However, when stored in databases, UUIDs can be compressed to 16 bytes of binary data, and some systems may display UUIDs without hyphens (32 characters) or in other formats.

How unique are UUIDs really?

The probability of generating a duplicate UUID v4 is extremely low - approximately 1 in 2¹²⁸ (or 1 in 340,282,366,920,938,463,463,374,607,431,768,211,456). To put this in perspective, you'd need to generate 2.71 quintillion UUIDs to have a 50% probability of finding a single duplicate.

How to generate a UUID?

UUIDs can be generated using built-in functions in most programming languages and frameworks. In modern browsers, you can use crypto.randomUUID(). Other common methods include uuid.uuid4() in Python, UUID.randomUUID() in Java, and Guid.NewGuid() in C#. Many databases also provide built-in UUID generation functions like uuid_generate_v4() in PostgreSQL.

Are UUIDs secure?

Version 4 UUIDs generated with proper random number generators (like our implementation using Web Crypto API) are suitable for most security-sensitive applications. However, they should not be used as encryption keys or passwords.

How do cryptographic random number generators work?

Cryptographic random number generators, like those used in crypto.randomUUID(), use hardware-based entropy sources and complex algorithms to generate high-quality random numbers. They collect unpredictable data from various system events, hardware timing, and other sources to ensure the generated numbers are truly random and cannot be predicted, making them suitable for security-critical applications.

Can UUIDs be used as database keys?

Yes, UUIDs are commonly used as primary keys in databases, especially in distributed systems. They offer advantages like guaranteed uniqueness across systems and better privacy compared to sequential IDs. However, they do require more storage space (16 bytes vs 4 bytes for regular integers) and can impact indexing performance due to their random nature.

What's the difference between UUID and GUID?

UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier) are essentially the same thing. GUID is Microsoft's implementation of the UUID standard. Both use the same format and serve the same purpose of providing unique identifiers. The term GUID is more commonly used in Microsoft technologies, while UUID is the standard term used elsewhere.

How unique are UUIDs really?

The probability of generating a duplicate UUID v4 is extremely low - approximately 1 in 2¹²⁸ (or 1 in 340,282,366,920,938,463,463,374,607,431,768,211,456). To put this in perspective, you'd need to generate 2.71 quintillion UUIDs to have a 50% probability of finding a single duplicate.

Are UUIDs secure?

Version 4 UUIDs generated with proper random number generators (like our implementation using Web Crypto API) are suitable for most security-sensitive applications. However, they should not be used as encryption keys or passwords.

Why are UUIDs so long?

The length of UUIDs (128 bits) was chosen to be sufficient for creating unique identifiers without coordination across systems. The hexadecimal representation makes them human-readable while maintaining their uniqueness properties.

How to Generate UUIDs in Different Programming Languages

Here are examples of how to generate random UUIDs (version 4) in various programming languages:

Python

Using the built-in uuid module:

import uuid
uuid_string = str(uuid.uuid4())

JavaScript

Using the crypto API (modern browsers):

const uuid = crypto.randomUUID();

Java

Using the built-in UUID class:

import java.util.UUID;
String uuid = UUID.randomUUID().toString();

C#

Using System.Guid:

using System;
string uuid = Guid.NewGuid().ToString();

PHP

Using the random_bytes function (PHP 7+):

$uuid = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex(random_bytes(16)), 4));

// Or using built-in function (PHP 7.2+):
$uuid = uuid_create();

Ruby

Using the SecureRandom module:

require 'securerandom'
uuid = SecureRandom.uuid

Go

Using the google/uuid package:

import "github.com/google/uuid"

id := uuid.New().String()

Rust

Using the uuid crate:

use uuid::Uuid;
let uuid = Uuid::new_v4().to_string();

Swift

Using Foundation's UUID:

import Foundation
let uuid = UUID().uuidString

TypeScript

Using the crypto API (same as JavaScript):

const uuid: string = crypto.randomUUID();

Note: Some implementations might require installing additional packages or libraries. Always check the official documentation for the most up-to-date methods and best practices for your specific use case.

Generating UUIDs in Databases

Here's how to generate UUIDs in popular database systems:

PostgreSQL

PostgreSQL has built-in UUID support with the uuid-ossp extension:

-- Enable the extension (one-time setup)
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- Generate UUID
SELECT uuid_generate_v4();

-- Create a table with UUID primary key
CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    name TEXT
);

MySQL

MySQL 8.0+ includes UUID generation functions:

-- Generate UUID
SELECT UUID();

-- Create a table with UUID primary key
CREATE TABLE users (
    id CHAR(36) PRIMARY KEY DEFAULT (UUID()),
    name TEXT
);

Microsoft SQL Server

SQL Server uses the term UNIQUEIDENTIFIER for UUIDs:

-- Generate new UUID (GUID in SQL Server terms)
SELECT NEWID();

-- Create a table with UUID primary key
CREATE TABLE users (
    id UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),
    name NVARCHAR(100)
);

Oracle

Oracle provides the SYS_GUID() function:

-- Generate UUID
SELECT SYS_GUID() FROM DUAL;

-- Create a table with UUID primary key
CREATE TABLE users (
    id RAW(16) DEFAULT SYS_GUID() PRIMARY KEY,
    name VARCHAR2(100)
);

SQLite

SQLite doesn't have built-in UUID generation, but you can create UUIDs using application code or user-defined functions:

-- Using a random blob (requires application code to format as UUID)
CREATE TABLE users (
    id TEXT PRIMARY KEY,  -- Store UUID as text
    name TEXT
);

-- Insert using application-generated UUID
INSERT INTO users (id, name) VALUES (generate_uuid(), 'John');

Database-specific notes:

  • PostgreSQL's uuid-ossp is the most complete UUID implementation among databases
  • MySQL stores UUIDs as CHAR(36) strings by default
  • SQL Server's UNIQUEIDENTIFIER is a 16-byte binary type
  • Oracle's RAW(16) stores the UUID in its most compact form
  • For SQLite, it's recommended to handle UUID generation in the application layer