Project

General

Profile

Actions

Feature #19735

closed

Add support for UUID version 7

Added by nevans (Nicholas Evans) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113926]

Description

Although the specification for UUIDv7 is still in draft, the UUIDv7 algorithm has been stable as the RFC progresses to completion.

Version 7 UUIDs can be very useful, because they are lexographically sortable, which can improve e.g: database index locality. See section 6.10 of the draft specification for further explanation:

https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/

require 'random/formatter'
Random.uuid_v7 # => "0188ca50-fcc0-7881-b5c5-6d55cd8fc373"
Random.uuid_v7 # => "0188ca51-0069-7304-be2e-0c3cd908789b"
Random.uuid_v7 # => "0188ca51-04aa-7b57-a6ec-c49573412a9d"
Random.uuid_v7 # => "0188ca51-0853-7979-ae37-485460e9f4f1"
# or
prng = Random.new
prng.uuid_v7 # => "0188ca51-5e72-7950-a11d-def7ff977c98"

PR here: https://github.com/ruby/securerandom/pull/19

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like1Like1