DevToolsForYou

UUID Generator in Ruby — Code Examples

UUID Generator in RubyUse the online tool →

UUIDs (Universally Unique Identifiers) are 128-bit identifiers used as database primary keys, session tokens, and idempotency keys. UUID v4 (random) is the safe default; UUID v7 (time-ordered) is preferred for database primary keys.

Ruby's built-in SecureRandom module generates UUID v4. For v5 or v7, use the uuidtools or uuid gems.

Ruby
require 'securerandom'

# UUID v4 — random (built-in, no gems required)
id = SecureRandom.uuid
puts id # e.g. 550e8400-e29b-41d4-a716-446655440000

# Multiple UUIDs
ids = Array.new(5) { SecureRandom.uuid }
puts ids

# Raw hex (UUID without dashes)
hex = SecureRandom.hex(16)
puts hex # e.g. 550e8400e29b41d4a716446655440000

# UUID v7 (time-ordered) via the 'uuidv7' gem
# gem install uuidv7
# require 'uuidv7'
# id7 = UUIDv7.generate
# puts id7
Notes & gotchas
  • SecureRandom.uuid generates a UUID v4 using the OS CSPRNG — no external gems needed.
  • For UUID v7 (time-ordered, better for database primary keys), use the uuidv7 gem.
  • SecureRandom.hex(16) generates 32 hex characters — the same entropy as a UUID but without the standard dashes.
Try it in your browser

Need to uuid generator without writing code? The UUID Generator runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.

Open UUID Generator
UUID Generator in other languages