ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Cryptography

UUID Generation

Generate RFC 4122 v4 and v7 UUIDs in the browser with crypto.getRandomValues().

3 snippets Beginner uuid-generator
UUIDRFC 4122v4v7identifiers

What you'll learn

  • UUID v4
  • UUID v7 (time-ordered)
  • crypto.randomUUID() (built-in)

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. Try the interactive related tool to see the concept in action.
Code Snippets

Copy-paste code snippets

3 ready-to-use snippets for uuid generation. Click copy and paste into your project.

UUID v4
                function uuidv4() {
  const arr = new Uint8Array(16);
  crypto.getRandomValues(arr);
  arr[6] = (arr[6] & 0x0f) | 0x40;  // version 4
  arr[8] = (arr[8] & 0x3f) | 0x80;  // variant 1
  const h = [...arr].map(b =>
    b.toString(16).padStart(2, '0'));
  return `${h[0]}${h[1]}${h[2]}${h[3]}-${h[4]}${h[5]}-${h[6]}${h[7]}-${h[8]}${h[9]}-${h[10]}${h[11]}${h[12]}${h[13]}${h[14]}${h[15]}`;
}
              
UUID v7 (time-ordered)
                function uuidv7() {
  const arr = new Uint8Array(16);
  crypto.getRandomValues(arr);

  // First 48 bits = Unix timestamp in ms
  const ts = Date.now();
  const view = new DataView(arr.buffer);
  view.setUint32(0, ts >> 16);
  view.setUint16(4, ts & 0xFFFF);

  arr[6] = (arr[6] & 0x0f) | 0x70;  // version 7
  arr[8] = (arr[8] & 0x3f) | 0x80;  // variant 1

  const h = [...arr].map(b =>
    b.toString(16).padStart(2, '0'));
  return h.slice(0,4).join('') + '-' +
    h.slice(4,6).join('') + '-' +
    h.slice(6,8).join('') + '-' +
    h.slice(8,10).join('') + '-' +
    h.slice(10,16).join('');
}
              
crypto.randomUUID() (built-in)
                // Modern browsers have built-in UUID v4
const id = crypto.randomUUID();
// "550e8400-e29b-41d4-a716-446655440000"

// Bulk generation
const ids = Array.from(
  { length: 1000 },
  () => crypto.randomUUID()
);
              
Tool

Try this concept hands-on with the interactive tool.

100% Free · No signup · No cost

Generate something unguessable right now

148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site