ulid

ULIDs for OCaml
README

ULIDs are

  • 128-bit compatibility with UUID
    1.21e+24 unique ULIDs per millisecond

  • Lexicographically sortable!

  • Canonically encoded as a 26 character string, as opposed to the 36 character UUID

  • Uses Crockford's base32 for better efficiency and readability (5 bits per character)

  • Case insensitive

  • No special characters (URL safe)

  • Monotonic sort order (correctly detects and handles the same millisecond)

See the full spec here.

This package uses nocrypto's fortuna RNG for the random part of the ULID, but a different generator can be passed in with the signature int -> int (to generate a random number between 0 and n-1).

Help is welcome!

Installation

ulid can be installed with opam:

opam install ulid

Usage

basic ulid generation:

let ulid = Ulid.ulid ();; (* something like 01D07HWDR77VCQ6CC8XSDC916T *)

passing in a seed time instead of current time (see spec for more details):

let ulid = Ulid.ulid ?seed_time:123 ();;

getting monotonic ulids:

let get_ulid = Ulid.monotonic_factory ();;
let ulid = get_ulid ();;

using a different PRNG:

let get_ulid = Ulid.ulid_factory ~prng:my_favorite_prng ();;
let ulid = get_ulid ();;

License

MIT

Install
Published
02 Jan 2019
Sources
0.1.tar.gz
md5=832e5db6c4a2d1cbc67e93cf75ea484f
sha512=f9ee4d4b960e923f8a6ff81d667d3228bf18df71ca6188cc512332dd61ad6e3635ae7e08aab7c5807656be42f72a4d57540ddb2e1916dd588881253994069619
Dependencies
alcotest
with-test
dune
>= "1.0.1"
Reverse Dependencies