UUID Generator

Generate random Universally Unique Identifiers (UUID v4) for creating globally unique identifiers. Each UUID is unique and can be used for database primary keys, distributed systems, and more.

UUID Implementation Guide

Learn about UUIDs and how to use them effectively in your applications.

What is a UUID?

  • Definition:
    • 128-bit identifier (32 hexadecimal digits)
    • Globally unique across space and time
    • Version 4 uses random or pseudo-random numbers
  • Format:
    xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
    // x is any hexadecimal digit
    // y is 8, 9, A, or B

When to Use UUIDs?

  • Common Use Cases:
    • Database primary keys
    • Distributed systems
    • Cross-system data synchronization
  • Code Example:
    // JavaScript UUID implementation
    function generateUUID() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
            const r = Math.random() * 16 | 0;
            return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
        });
    }

Best Practices

  • Storage: Use binary format in databases for efficiency
  • Indexing: Consider impact on database index size
  • Validation: Always verify UUID format before use
  • Security: Use cryptographically secure random number generators