Generate random UUID v4 identifiers.
A UUID (Universally Unique Identifier) is a 128-bit identifier standardized by RFC 4122. UUIDs are designed to be unique across all devices, databases, and time without requiring a central authority to issue them. This makes them ideal for distributed systems where coordination between nodes is impractical.
Version 4 UUIDs are the most commonly used type. They are generated using random or pseudo-random numbers, with 122 bits of randomness giving approximately 5.3 x 1036 possible values. The probability of generating two identical UUID v4 values is so small that it is considered practically impossible.
Format:
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
4 = version indicator, y = variant (8, 9, a, or b)
| Version | Based On | Use Case |
|---|---|---|
| v1 | Timestamp + MAC | Time-ordered, reveals hardware |
| v4 | Random | General purpose (most common) |
| v5 | SHA-1 hash | Deterministic from namespace + name |
| v7 | Timestamp + random | Sortable, database-friendly |
// Node.js (built-in since v14.17)
import { randomUUID } from 'crypto';
const uuid = randomUUID();
// e.g. "550e8400-e29b-41d4-a716-446655440000"
// Browser (modern)
const uuid = crypto.randomUUID();
// Manual implementation (older environments)
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
/[xy]/g, c => {
const r = Math.random() * 16 | 0;
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
}
);
}
import uuid
# Generate UUID v4 (random)
id = uuid.uuid4()
print(id) # e.g. 550e8400-e29b-41d4-a716-446655440000
# Generate UUID v5 (deterministic)
id = uuid.uuid5(uuid.NAMESPACE_DNS, "example.com")
# Convert to string without hyphens
print(id.hex) # "550e8400e29b41d4a716446655440000"
package main
import (
"fmt"
"github.com/google/uuid"
)
func main() {
// Generate UUID v4
id := uuid.New()
fmt.Println(id.String())
// Parse a UUID string
parsed, err := uuid.Parse("550e8400-e29b-41d4-a716-446655440000")
if err != nil {
panic(err)
}
fmt.Println(parsed.Version()) // 4
}
# Linux
cat /proc/sys/kernel/random/uuid
# macOS
uuidgen | tr '[:upper:]' '[:lower:]'
# Using Python one-liner
python3 -c "import uuid; print(uuid.uuid4())"
uuid type that stores them efficiently as 16 bytes.
Building distributed systems with UUIDs? Make sure your services stay up. UptimeSignal monitors your endpoints and alerts you the moment something goes down.
Start monitoring free →25 monitors free. No credit card required.