Home

Awesome

ULID

Tests

An OTP library for generating Universally Unique Lexicographically Sortable Identifiers.

Build

$ make

Run tests

$ make test

Usage

Add to rebar:

{deps, [
    {ulid, {git, "https://github.com/savonarola/ulid.git", {tag, "0.1.1"}}}
]}.

Generate universally unique identifiers: The first 10 characters are encoded timestamps with millisecond precision, so these identifiers (generally) ascend from millisecond to millisecond (but unordered within the same millisecond). Using a generator, one can generate monotonically increasing identifiers (i.e. identifiers generated by the same generator are always ascending, assuming time is monotonic):

1> Gen0 = ulid:new(),
    {Gen1, Ulid1} = ulid:generate(Gen0),
    {Gen2, Ulid2} = ulid:generate(Gen1),
    {Gen3, Ulid3} = ulid:generate_list(Gen2),
    [Ulid1, Ulid2, Ulid3].
[<<"01ASXQ4J7ZT1XEZJFJFHE7G5R0">>,
 <<"01ASXQ4J7ZT1XEZJFJFHE7G5R1">>,
  "01ASXQ4J7ZT1XEZJFJFHE7G5R2"]