🍋
Menu
Developer

UUID

Universally Unique Identifier

A 128-bit identifier guaranteed to be unique across space and time, formatted as a 36-character string.

Detalhe técnico

RFC 9562 defines UUID versions 1-8. Version 4 (random) is most common: 122 random bits yield a collision probability of ~10^-18 per billion IDs. Version 7 (2024) combines a Unix timestamp millisecond prefix with random bits, producing time-sortable UUIDs ideal for database primary keys. The standard format is 8-4-4-4-12 hexadecimal characters (32 hex digits, 4 hyphens). Database storage is most efficient as BINARY(16) rather than CHAR(36) — saving 20 bytes per row.

Exemplo

```javascript
// Generate UUID v4 (cryptographically random)
const uuid = crypto.randomUUID();
// → 'a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d'

// Validate UUID format
const isValid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid);
```

Ferramentas relacionadas

Termos relacionados