uuid Examples You Can Edit and Run
5 small uuid examples written by AgentGid from the official docs, one feature each. Every one runs in your browser: change the code and see the result at once, or describe a change and let AI rewrite it. The screenshots are taken from the same code by our server, which also checks that each example starts without errors.
uuid: usage and stats 292 AI-built projects use it
Random UUIDs with uuid v4Run it a few times: the plain v4() lines change, the fixed-bytes line stays 109156be-c4fb-41ea-b1b4-efe1671c5836.
Time-based UUIDs with uuid v7The decoded time of v7 #1 is the moment you ran the code; change the date in Date.UTC to move the fixed one.
Name-based UUIDs with uuid v5Change "Hello, World!" or an email and the UUID changes; run again with the same text and it stays the same.
Validating UUIDs with uuidAdd your own strings to the samples object and see which ones pass.
Converting UUIDs to bytes with uuidChange the id string and compare its hex pairs with the bytes line.
Try them all in one place
import { v4 as uuidv4 } from 'uuid'
// Each call returns a new random UUID string
console.log('v4 #1:', uuidv4())
console.log('v4 #2:', uuidv4())
console.log('v4 #3:', uuidv4())
// Give every record its own id
const todos = ['Write docs', 'Ship release', 'Reply to issues'].map((title) => ({ id: uuidv4(), title }))
for (const t of todos) console.log(`todo "${t.title}" ->`, t.id)
// rng option: a function that returns 16 random bytes
const rng = () => crypto.getRandomValues(new Uint8Array(16))
console.log('with rng option:', uuidv4({ rng }))
// random option: fixed bytes always give the same UUID
const random = Uint8Array.of(
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
)
console.log('with fixed random bytes:', uuidv4({ random }))
console.log('string length:', uuidv4().length)
Run it a few times: the plain v4() lines change, the fixed-bytes line stays 109156be-c4fb-41ea-b1b4-efe1671c5836. Code written by AgentGid [1]. How it works, with a screenshot →
Run it a few times: the plain v4() lines change, the fixed-bytes line stays 109156be-c4fb-41ea-b1b4-efe1671c5836. Code written by AgentGid [1]. How it works, with a screenshot →The decoded time of v7 #1 is the moment you ran the code; change the date in Date.UTC to move the fixed one. Code written by AgentGid [1]. How it works, with a screenshot →Change "Hello, World!" or an email and the UUID changes; run again with the same text and it stays the same. Code written by AgentGid [1]. How it works, with a screenshot →Add your own strings to the samples object and see which ones pass. Code written by AgentGid [1]. How it works, with a screenshot →Change the id string and compare its hex pairs with the bytes line. Code written by AgentGid [1]. How it works, with a screenshot →Checked Oct 12, 2026: each example starts without errors in Chromium with uuid 14.0.3. Needs WebGL.
Sources
Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.