Generador de UUID

Genera y valida UUID (v1, v4, v5, v7), con soporte para generación por lotes y múltiples opciones de formato, además de ejemplos de código en varios idiomas.

Generador de UUID

Opciones de formato

Validador de UUID

Instrucciones de uso

Un UUID es un identificador de 128 bits, representado normalmente como 36 caracteres con guiones.
UUID v1: Basado en marca de tiempo e información de la tarjeta de red; ordenable por tiempo, pero puede revelar fecha/hora o ubicación.
UUID v4: Basado en números aleatorios; el más común, ofrece buena unicidad y privacidad.
UUID v7: Basado en tiempo Unix en milisegundos + aleatoriedad; naturalmente ordenable y evita los problemas de privacidad de v1.
UUID v5: Basado en un espacio de nombres UUID y un nombre, calculado mediante SHA-1; produce siempre el mismo resultado para entradas idénticas.
Formato estándar: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (36 caracteres).

Características

  • Soporta UUID v1, v4, v5 y v7
  • Generación por lotes con cantidad personalizable
  • Formato flexible: mayúsculas, sin guiones, con llaves
  • Validador integrado con detección automática de versión
  • Soporte completo para internacionalización y temas múltiples

¿Qué es un UUID?

Un UUID es un identificador de 128 bits, representado normalmente como 36 caracteres con guiones.

UUID v1: Basado en marca de tiempo e información de la tarjeta de red; ordenable por tiempo, pero puede revelar fecha/hora o ubicación.

UUID v4: Basado en números aleatorios; el más común, ofrece buena unicidad y privacidad.

UUID v7: Basado en tiempo Unix en milisegundos + aleatoriedad; naturalmente ordenable y evita los problemas de privacidad de v1.

UUID v5: Basado en un espacio de nombres UUID y un nombre, calculado mediante SHA-1; produce siempre el mismo resultado para entradas idénticas.

UUID Ejemplos rápidos

Formato estándar:
550e8400-e29b-41d4-a716-446655440000
Formato en mayúsculas:
550E8400-E29B-41D4-A716-446655440000
Sin guiones:
550e8400e29b41d4a716446655440000
Con llaves:
{550e8400-e29b-41d4-a716-446655440000}

UUID Casos de uso comunes

  • Identificadores únicos para registros de base de datos o recursos
  • Trace ID para registro y seguimiento de eventos
  • Identificadores públicos difíciles de adivinar
  • Identificadores unificados en interfaces entre sistemas

UUID Preguntas frecuentes y trampas

  • v1 y privacidad: v1 puede revelar fecha/hora o ubicación; para mayor privacidad, se recomienda usar v4.
  • ¿Son equivalentes mayúsculas y minúsculas?: Sí, las comparaciones son insensibles a mayúsculas/minúsculas.
  • Los guiones solo sirven para legibilidad; a menos que haya restricciones, se recomienda conservarlos.
  • El formato con llaves es aceptado en algunos entornos (por ejemplo, Registro de Windows).
  • v5 es determinista (mismo espacio de nombres + mismo nombre => mismo UUID). Ideal para escenarios idempotentes; no adecuado cuando se requiere impredecibilidad.

Cómo usar UUID en lenguajes de programación

JavaScript
Generar
// UUID v4 (simple)
function uuidv4(){
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
    const r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
    return v.toString(16);
  });
}
const id = uuidv4();
UUID v7 (tiempo Unix + aleatorio)
// UUID v7 (Unix ms + randomness)
function uuidv7(){
  const cryptoObj = (globalThis.crypto || globalThis.msCrypto);
  const rb = n => { const a = new Uint8Array(n); cryptoObj?.getRandomValues ? cryptoObj.getRandomValues(a) : a.forEach((_,i)=>a[i]=Math.random()*256|0); return a; };
  const hex = b => Array.from(b).map(x=>x.toString(16).padStart(2,'0')).join('');
  const ts = BigInt(Date.now()).toString(16).padStart(12,'0');
  const ver = rb(2); ver[0] = (ver[0] & 0x0f) | 0x70;    // set version 7
  const vrn = rb(2); vrn[0] = (vrn[0] & 0x3f) | 0x80;    // RFC4122 variant
  const tail = rb(6);
  return `${ts.slice(0,8)}-${ts.slice(8,12)}-${hex(ver)}-${hex(vrn)}-${hex(tail)}`;
}
const id7 = uuidv7();
Validar
const re=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-57][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
re.test(id); // true/false
PHP
Generar
<?php
// v4 using random_bytes
function uuidv4(){
  $data = random_bytes(16);
  $data[6] = chr((ord($data[6]) & 0x0f) | 0x40);
  $data[8] = chr((ord($data[8]) & 0x3f) | 0x80);
  return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
$id = uuidv4();
UUID v7 (tiempo Unix + aleatorio)
<?php
// composer require ramsey/uuid:^4.7
use Ramsey\Uuid\Uuid;

$uuid7 = Uuid::uuid7();
Validar
<?php
$re = '/^[0-9a-f]{8}-[0-9a-f]{4}-[1-57][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i';
preg_match($re, $id) === 1; // true/false
Python
Generar
import uuid
# v4
uid = uuid.uuid4()
# v1
uid1 = uuid.uuid1()
UUID v7 (tiempo Unix + aleatorio)
# pip install uuid6
from uuid6 import uuid7

uid7 = uuid7()
Validar
import re
re_uuid = re.compile(r'^[0-9a-f]{8}-[0-9a-f]{4}-[1-57][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', re.I)
bool(re_uuid.match(str(uid)))
Go
Generar
// go get github.com/google/uuid
import "github.com/google/uuid"

id := uuid.New()     // v4
id1 := uuid.NewUUID() // v1 (may return error)
UUID v7 (tiempo Unix + aleatorio)
// go get github.com/gofrs/uuid/v5
import (
  uuid "github.com/gofrs/uuid/v5"
)

id7, err := uuid.NewV7()
Validar
import "github.com/google/uuid"
_, err := uuid.Parse(id.String()) // err == nil means valid
Rust
Generar
// Cargo.toml: uuid = { version = "1", features = ["v4", "v1"] }
use uuid::Uuid;

let v4 = Uuid::new_v4();
// v1 requires a context/ts, often via external crate; shown for completeness
UUID v7 (tiempo Unix + aleatorio)
// Cargo.toml: uuid = { version = "1", features = ["v7"] }
use uuid::Uuid;

let v7 = Uuid::now_v7();
Validar
use uuid::Uuid;
let ok = Uuid::parse_str(v4.to_string().as_str()).is_ok();
Java
Generar
import java.util.UUID;

UUID id = UUID.randomUUID(); // v4
UUID v7 (tiempo Unix + aleatorio)
// Maven: com.github.f4b6a3:uuid-creator
import com.github.f4b6a3.uuid.UuidCreator;

UUID v7 = UuidCreator.getTimeOrderedEpoch(); // UUIDv7
Validar
import java.util.UUID;

try { UUID.fromString(id.toString()); /* valid */ } catch (IllegalArgumentException ex) { /* invalid */ }