Portable UUIDv7 generator for Clojure, ClojureScript, Babashka, nbb, and scittle.
Implements RFC 9562 Section 6.2 Method 3 (monotonic random):
Usage: (require '[com.github.franks42.uuidv7.core :refer [uuidv7]]) (uuidv7) ;=> #uuid "0195xxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx"
;; Extract embedded data: (extract-ts u) ;=> 1738934578991 (ms since epoch) (extract-inst u) ;=> #inst "2025-02-07..." (as Date) (extract-key u) ;=> [ts a bh bl] (sortable composite key)
The 74-bit counter space (~1.9 * 10^22 values per millisecond) is effectively inexhaustible. On each new millisecond the counter reseeds with fresh random bits. Within the same millisecond it increments by a random amount (1 to 2^31), preserving both monotonicity and unpredictability.
Portable UUIDv7 generator for Clojure, ClojureScript, Babashka, nbb, and scittle. Implements RFC 9562 Section 6.2 Method 3 (monotonic random): - 48-bit millisecond Unix timestamp - 74-bit monotonically increasing random counter - Sub-millisecond ordering guaranteed from a single generator - No blocking, no spinning, no overflow in practice Usage: (require '[com.github.franks42.uuidv7.core :refer [uuidv7]]) (uuidv7) ;=> #uuid "0195xxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx" ;; Extract embedded data: (extract-ts u) ;=> 1738934578991 (ms since epoch) (extract-inst u) ;=> #inst "2025-02-07..." (as Date) (extract-key u) ;=> [ts a bh bl] (sortable composite key) The 74-bit counter space (~1.9 * 10^22 values per millisecond) is effectively inexhaustible. On each new millisecond the counter reseeds with fresh random bits. Within the same millisecond it increments by a random amount (1 to 2^31), preserving both monotonicity and unpredictability.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |