Developer
UUID GENERATOR
Generate UUIDs v4 (random) and v7 (time-ordered) in bulk. Multiple formats. Pure browser generation.
Developer Reference
Core Algorithm & Standalone Script
Standalone, zero-dependency JavaScript implementation powering this tool. Free to inspect, copy, and build upon.
function uuidv4() {
if (crypto.randomUUID) return crypto.randomUUID();
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = crypto.getRandomValues(new Uint8Array(1))[0] % 16;
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}
function uuidv7() {
const ms = BigInt(Date.now());
const rand = new Uint8Array(10);
crypto.getRandomValues(rand);
const hi = ms >> 12n;
const lo = ms & 0xfffn;
const b = new Uint8Array(16);
// Bytes 0-5: 48-bit timestamp
b[0] = Number((hi >> 8n) & 0xffn);
b[1] = Number(hi & 0xffn);
b[2] = Number((ms >> 24n) & 0xffn);
b[3] = Number((ms >> 16n) & 0xffn);
b[4] = Number((ms >> 8n) & 0xffn);
b[5] = Number(ms & 0xffn);
// Byte 6: version (7)
b[6] = 0x70 | (rand[0] & 0x0f);
b[7] = rand[1];
// Byte 8: variant (10xx)
b[8] = 0x80 | (rand[2] & 0x3f);
for (let i = 9; i < 16; i++) b[i] = rand[i - 7];
const hex = Array.from(b).map(x => x.toString(16).padStart(2,'0')).join('');
return `${hex.slice(0,8)}-${hex.slice(8,12)}-${hex.slice(12,16)}-${hex.slice(16,20)}-${hex.slice(20)}`;
}
function applyFormat(uuid) {
const fmt = document.getElementById('format').value;
if (fmt === 'upper') return uuid.toUpperCase();
if (fmt === 'nohyphen') return uuid.replace(/-/g, '');
if (fmt === 'urn') return 'urn:uuid:' + uuid;
return uuid;
}
const INFO = {
v4: 'UUID v4 is generated using <strong>cryptographically secure random numbers</strong>. Each UUID is completely random and has no structure encoding time or location.',
v7: 'UUID v7 uses a <strong>Unix millisecond timestamp</strong> in the most significant bits, making them sortable by creation time. Ideal for database primary keys.',
};
function updateInfo() {
document.getElementById('versionInfo').innerHTML = INFO[document.getElementById('version').value];
}
let lastUUIDs = [];
function generate() {
const ver = document.getElementById('version').value;
const count = parseInt(document.getElementById('count').value);
lastUUIDs = Array.from({ length: count }, () => ver === 'v7' ? uuidv7() : uuidv4());
const html = lastUUIDs.map((uuid, i) => {
const display = applyFormat(uuid);
return `<div class="uuid-item">
<div class="uuid-num">${i+1}</div>
<div class="uuid-text">${display}</div>
<button class="uuid-copy" onclick="copyOne('${display}', this)">copy</button>
</div>`;
}).join('');
document.getElementById('uuidList').innerHTML = html;
document.getElementById('copyAllBtn').textContent = 'Copy All';
document.getElementById('copyAllBtn').classList.remove('copied');
}
function copyOne(text, btn) {
navigator.clipboard.writeText(text).catch(() => {});
btn.textContent = 'copied!'; btn.classList.add('copied');
setTimeout(() => { btn.textContent = 'copy'; btn.classList.remove('copied'); }, 2000);
}
function copyAll() {
const fmt = document.getElementById('format').value;
const text = lastUUIDs.map(u => applyFormat(u)).join('\n');
navigator.clipboard.writeText(text).catch(() => {});
const btn = document.getElementById('copyAllBtn');
btn.textContent = 'Copied!'; btn.classList.add('copied');
setTimeout(() => { btn.textContent = 'Copy All'; btn.classList.remove('copied'); }, 2000);
}
function showSpecial(type) {
const val = type === 'nil' ? '00000000-0000-0000-0000-000000000000' : 'ffffffff-ffff-ffff-ffff-ffffffffffff';
document.getElementById('specialOutput').textContent = `${type === 'nil' ? 'Nil' : 'Max'} UUID: ${val}`;
navigator.clipboard.writeText(val).catch(() => {});
}
updateInfo();
generate();