ULID Generator
Genera identificatori univoci lessicograficamente ordinabili
Il tuo ULID
Formato
Crockford Base32
Lunghezza
26 caratteri
Timestamp
-
Ordinabilità
Lessicografica
Ordinabile: Gli ULID sono ordinabili lessicograficamente per timestamp
Compatto: 26 caratteri vs 36 caratteri di UUID
Case Insensitive: Usa Crockford Base32 (no I, L, O, U)
80 bit random: Entropia sufficiente per evitare collisioni
JavaScript
// ULID - Universally Unique Lexicographically Sortable Identifier
const ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
function generateUlid() {
const now = Date.now();
// Encode timestamp (48 bits = 10 chars)
let timestamp = '';
let time = now;
for (let i = 0; i < 10; i++) {
timestamp = ENCODING[time % 32] + timestamp;
time = Math.floor(time / 32);
}
// Generate random part (80 bits = 16 chars)
const randomBytes = new Uint8Array(10);
crypto.getRandomValues(randomBytes);
let random = '';
for (let i = 0; i < 10; i++) {
const byte = randomBytes[i];
random += ENCODING[(byte >> 3) & 0x1f];
if (i < 9) {
random += ENCODING[((byte & 0x07) << 2) |
(randomBytes[i + 1] >> 6)];
i++;
}
}
random = random.slice(0, 16);
return timestamp + random;
}