Home

Awesome

Universally Unique Lexicographically Sortable Identifier for Lua

Based on the implementation by alizain

UUID can be suboptimal for many uses-cases because:

Instead, herein is proposed ULID:

Lua

Installation

luarocks install ulid

Usage

local ulid_mod = require("ulid")

print(ulid_mod.ulid())  -- 01ARZ3NDEKTSV4RRFFQ69G5FAV

Specification

Below is the current specification of ULID as implemented in this repository.

Note: the binary format has not been implemented.

 01AN4Z07BY      79KA1307SR9X4MV3

|----------|    |----------------|
 Timestamp          Randomness
   48bits             80bits

Components

Timestamp

Randomness

Sorting

The left-most character must be sorted first, and the right-most character sorted last (lexical order). The default ASCII character set must be used. Within the same millisecond, sort order is not guaranteed

Encoding

Crockford's Base32 is used as shown. This alphabet excludes the letters I, L, O, and U to avoid confusion and abuse.

0123456789ABCDEFGHJKMNPQRSTVWXYZ

String Representation

ttttttttttrrrrrrrrrrrrrrrr

where
t is Timestamp
r is Randomness

Test Suite

Tests can be run from the repo using busted

busted