Universally Unique Identifiers (UUID) & Database Indexing
A UUID (Universally Unique Identifier), also known as a GUID, is a 128 bit label used for information in computer systems. They are critical for identifying database rows without requiring a centralized, auto incrementing integer server.
Generating UUIDs for secure API tokens or session IDs requires cryptographic entropy. This generator leverages the `crypto.getRandomValues()` API natively in your browser, generating RFC 4122 compliant Version 4 UUIDs entirely client side.
Core Architecture & Mathematical Formula
UUID v4 = 32 Hexadecimal Characters (128 bits) driven by Cryptographic Pseudorandom Number Generators (CPRNG)
A standard UUID looks like this: `123e4567-e89b-12d3-a456-426614174000`. In a Version 4 UUID, the 13th character is always '4', and the 17th character is always '8', '9', 'a', or 'b'.
Best Practices & Essential Guidelines
- Avoid UUIDs for Clustered Indexes: Because Version 4 UUIDs are completely random, inserting them into a standard SQL database causes massive index fragmentation. Use them as secondary keys, or use sequential UUIDs (ULID/UUIDv7) for primary keys.
- Never Use Math.random(): Standard programming random functions are highly predictable. Always ensure your UUID generator uses a secure cryptographic library to prevent attackers from guessing future session IDs.
- Store as BINARY(16) to Save Space: Storing a UUID as a 36 character string (VARCHAR) wastes massive database space. Converting the UUID to raw binary reduces the storage footprint from 36 bytes down to just 16 bytes.