Modern browsers and Node.js (18+) support crypto.randomUUID() natively โ no package install needed:
// Browser or Node.js 18+
const id = crypto.randomUUID();
console.log(id); // e.g. "3fa85f64-5717-4562-b3fc-2c963f66afa6"
For older Node.js versions, use the built-in crypto module or the popular uuid npm package:
// Node.js < 18, via built-in crypto module
const { randomUUID } = require('crypto');
const id = randomUUID();
// Or via the "uuid" npm package (npm install uuid)
import { v4 as uuidv4 } from 'uuid';
const id2 = uuidv4();
Python's standard library has had UUID support built in since Python 2.5 โ no pip install required:
import uuid
id = uuid.uuid4()
print(id) # 3fa85f64-5717-4562-b3fc-2c963f66afa6
print(str(id)) # as a string
print(id.hex) # without hyphens: 3fa85f6457174562b3fc2c963f66afa6
-- Postgres 13+: built-in, no extension needed
SELECT gen_random_uuid();
-- Older Postgres: enable the extension once
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
SELECT gen_random_uuid();
-- As a table column default
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT
);
-- Built-in function, returns a UUID v1 (timestamp + MAC) by default
SELECT UUID();
-- MySQL stores it as a string (CHAR(36)) unless you convert it
INSERT INTO users (id, name) VALUES (UUID(), 'Alice');
-- Returns a GUID (Microsoft's UUID implementation)
SELECT NEWID();
-- As a table column default
CREATE TABLE users (
id UNIQUEIDENTIFIER DEFAULT NEWID(),
name NVARCHAR(100)
);
-- No native UUID function โ generate in application code
-- and store as TEXT, or use a random-blob expression:
SELECT lower(hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-4' ||
substr(hex(randomblob(2)),2) || '-' ||
substr('89ab',abs(random()) % 4 + 1, 1) || substr(hex(randomblob(2)),2) || '-' ||
hex(randomblob(6)));
If you just need a batch of UUIDs to paste into a seed file, test fixture, or spreadsheet, skip the code entirely โ generate them directly in your browser instead.
Bulk-generate up to 50 random UUID v4 identifiers, free and instant, no code required.
Open UUID Generator โUUID() generates a version 1 UUID (timestamp + MAC address based). If you need a v4 random UUID in MySQL 8.0+, use UUID_TO_BIN(UUID(), 1) is not a v4 converter โ instead generate it in application code with your language's UUID library and pass it in, or use REPLACE(UUID(), '-', '') combined with random functions if you specifically need randomness at the database layer.