Standard library · Encoding and data

encoding.ulid

Sortable unique identifiers: ULID text and binary forms, a thread safe monotonic generator, and range bounds for queries.

import encoding.ulid

A ULID is a 128 bit identifier made of a 48 bit timestamp in milliseconds and 80 random bits, written as 26 characters of Crockford base32. It is the sortable alternative to a random UUID: the text sorts in the order the ids were made, so a database index stays compact and a range of time is a range of ids. This package follows the ULID specification and is written in Salam.

The text uses the digits and the letters without I, L, O and U. The largest id is 7ZZZZZZZZZZZZZZZZZZZZZZZZZ, because 130 bits are used to hold 128. Parsing accepts lowercase, reads I and L as 1 and O as 0, and refuses U and anything above that largest id.

PieceWhat it is
ULIDThe value: time plus two 40 bit halves of the randomness. Compare with Compare, Equal and Less.
New, NewString, NewBatchIds from the default generator. Strictly increasing in one process, safe from any number of threads.
GeneratorThe monotonic generator of the specification, one lock around the last id. NewGeneratorWith takes your clock and entropy.
Parse, StringText in and out. Bytes and FromBytes give the 16 bytes, also the bytes of a UUID.
FromPartsA time and 10 given bytes: no randomness, for exact tests.
MinAt, MaxAtThe first and the last id of a millisecond, the bounds of a range query.

Make, print and read back

New gives the next id of the default generator and String writes the 26 characters. NewAt makes an id for a time you choose. Every id is a value: copy it, compare it, keep it in a struct.

encoding-ulid-guide-basics.salam
import encoding.ulid

func main:
    id := ulid.New()
    text := ulid.String(id)
    println "length:", text.Len()
    back := ulid.Parse(text)
    println "round trip:", back.ok and ulid.Equal(back.id, id)
    println "close to now:", ulid.Time(id) - ulid.Now() < 5000
    stamp := ulid.NewAt(1469918176385)
    println ulid.String(stamp.id).Len(), ulid.Time(stamp.id)
end
Outputlength: 26 round trip: true close to now: true 26 1469918176385

Parsing and the rules of the text

Parse follows the specification: lowercase and the aliases I, L and O are accepted, U is not, and the first character may not be above 7 because the value would not fit in 128 bits. ParseStrict wants exactly what String writes. Errors are codes, with ErrorText for a message.

encoding-ulid-guide-parse.salam
import encoding.ulid

func show(text: str):
    r := ulid.Parse(text)
    if r.ok:
        println text, "->", ulid.Time(r.id), ulid.String(r.id)
    else:
        println text, "->", ulid.ErrorText(r.err)
    end
end

func main:
    show("01ARYZ6S41TSV4RRFFQ69G5FAV")
    show("01aryz6s41tsv4rrffq69g5fav")
    show("O1ARYZ6S41TSV4RRFFQ69G5FAV")
    show("7ZZZZZZZZZZZZZZZZZZZZZZZZZ")
    show("80000000000000000000000000")
    show("01ARYZ6S41TSV4RRFFQ69G5FAU")
    show("01ARYZ6S41")
    println ulid.ParseStrict("01aryz6s41tsv4rrffq69g5fav").ok
    println ulid.ParseStrict("01ARYZ6S41TSV4RRFFQ69G5FAV").ok
end
Output01ARYZ6S41TSV4RRFFQ69G5FAV -> 1469918176385 01ARYZ6S41TSV4RRFFQ69G5FAV 01aryz6s41tsv4rrffq69g5fav -> 1469918176385 01ARYZ6S41TSV4RRFFQ69G5FAV O1ARYZ6S41TSV4RRFFQ69G5FAV -> 1469918176385 01ARYZ6S41TSV4RRFFQ69G5FAV 7ZZZZZZZZZZZZZZZZZZZZZZZZZ -> 281474976710655 7ZZZZZZZZZZZZZZZZZZZZZZZZZ 80000000000000000000000000 -> ULID value is larger than 7ZZZZZZZZZZZZZZZZZZZZZZZZZ 01ARYZ6S41TSV4RRFFQ69G5FAU -> invalid character in ULID 01ARYZ6S41 -> a ULID is 26 characters false true

Order and range queries

Text order is time order, so ids sort by a plain string sort. To select the ids of a time window ask for everything between MinAt(start) and MaxAt(end); in SQL that is a BETWEEN on the id column.

encoding-ulid-guide-order.salam
import encoding.ulid

func main:
    mut ids := Vector {} as Vector<ulid.ULID>
    defer ids.free()
    mut mark := 1700000000000 as i64
    repeat 4:
        ids.push(ulid.MinAt(mark))
        mark += 1500
    end
    repeat ids.Len() in i:
        println ulid.String(ids.get(i))
    end

    low := ulid.MinAt(1700000001000)
    high := ulid.MaxAt(1700000003000)
    println "range:", ulid.String(low), ulid.String(high)
    repeat ids.Len() in i:
        inside := ulid.Compare(ids.get(i), low) >= 0 and ulid.Compare(ids.get(i), high) <= 0
        println i, inside
    end
end
Output01HF7YAT000000000000000000 01HF7YAVEW0000000000000000 01HF7YAWXR0000000000000000 01HF7YAYCM0000000000000000 range: 01HF7YATZ80000000000000000 01HF7YAWXRZZZZZZZZZZZZZZZZ 0 false 1 true 2 true 3 false

The monotonic generator

Two ids made in the same millisecond must still sort in the order they were made. A Generator does what the specification says: in a new millisecond it draws fresh randomness, in the same one it adds 1 to the last random part, and when the clock moves back it keeps the last timestamp. If the 80 bits ever overflow, the timestamp moves one millisecond ahead instead of failing. The example uses a fake clock and a fixed entropy function so every character is known.

encoding-ulid-guide-monotonic.salam
import encoding.ulid

mut now_ms := 1000 as i64
mut chunk := 7 as i64

func clock(): i64:
    ret now_ms
end

func source(): i64:
    ret chunk
end

func main:
    g := ulid.NewGeneratorWith((): ret clock() end, (): ret source() end)
    defer ulid.Free(g)
    repeat 3:
        println ulid.String(ulid.Next(g).id)
    end
    now_ms = 1001
    chunk = 9
    println ulid.String(ulid.Next(g).id)
    now_ms = 900
    last := ulid.Next(g)
    println "clock went back:", ulid.Time(last.id), ulid.String(last.id)
    println ulid.String(ulid.Increment(last.id).id)
end
Output00000000Z80000000700000007 00000000Z80000000700000008 00000000Z80000000700000009 00000000Z90000000900000009 clock went back: 1001 00000000Z9000000090000000A 00000000Z9000000090000000B

Many threads

The default generator and every Generator guard their state with a mutex, so threads share one without duplicates and without going out of order: every thread sees its own ids increase, and all ids together are distinct. NewBatch takes the lock once for n ids. The cost is one lock and one clock read per id.

encoding-ulid-guide-threads.salam
import encoding.ulid
import pool
import mem

const WORKERS := 8
const EACH := 500

func main:
    out := mem.AllocateZeroed((WORKERS * EACH * 3 * 8) as u64) as i64*
    shared := ulid.Default()
    pool.ParallelFor(WORKERS as i64, 4 as i64, (task: i64):
        repeat EACH in k:
            id := ulid.New()
            slot := ((task * EACH + k) * 3) as int
            out[slot] = id.time
            out[slot + 1] = id.hi
            out[slot + 2] = id.lo
        end
    end)
    mut seen := HashMap {} as HashMap<str, bool>
    defer seen.free()
    repeat WORKERS * EACH in n:
        id := ulid.ULID { time = out[n * 3], hi = out[n * 3 + 1], lo = out[n * 3 + 2] }
        seen.put(ulid.String(id), true)
    end
    println "ids:", WORKERS * EACH, "distinct:", seen.size()
    println ulid.Last(shared).ok
    mem.Free(out as void*)
end
Outputids: 4000 distinct: 4000 true

When the random source fails

The built in source reads the operating system random generator through crypto.RandomBytes, which stops the program if the system cannot give random bytes: a weak id is never made. A source of your own, passed to NewGeneratorWith, can fail politely by returning a negative number. Next then returns ERR_ENTROPY and leaves the generator untouched, so the next call can succeed.

encoding-ulid-guide-entropy.salam
import encoding.ulid

mut failing := true

func clock(): i64:
    ret 5000
end

func source(): i64:
    if failing:
        ret -1
    end
    ret 123456
end

func main:
    g := ulid.NewGeneratorWith((): ret clock() end, (): ret source() end)
    defer ulid.Free(g)
    r := ulid.Next(g)
    println r.ok, r.err == ulid.ERR_ENTROPY, ulid.ErrorText(r.err)
    println "state untouched:", ulid.Last(g).ok
    failing = false
    ok := ulid.Next(g)
    println ok.ok, ulid.String(ok.id)
end
Outputfalse true the entropy source failed state untouched: false true 00000004W800003RJ000003RJ0

Bytes, UUIDs and fixed ids

Bytes gives 16 bytes, big endian, the same size as a UUID, and FromBytes reads them back; the package does not depend on a UUID type, only on the bytes. FromParts builds an id from a time and 10 bytes you pick, which is how tests get exact answers. Free the byte vectors.

encoding-ulid-guide-bytes.salam
import encoding.ulid
import str

func hex(data: Vector<u8>): str:
    digits := "0123456789abcdef"
    mut out := ""
    repeat data.Len() in i:
        code := data.get(i) as int
        out = out + str.Substr(digits, code / 16, 1) + str.Substr(digits, code % 16, 1)
    end
    ret out
end

func main:
    r := ulid.Parse("01ARYZ6S41TSV4RRFFQ69G5FAV")
    raw := ulid.ToUUIDBytes(r.id)
    defer raw.free()
    println raw.Len(), hex(raw)
    back := ulid.FromUUIDBytes(raw)
    println back.ok, ulid.String(back.id)

    mut seed := Vector {} as Vector<u8>
    defer seed.free()
    repeat 10 in i:
        seed.push((i * 3) as u8)
    end
    made := ulid.FromParts(1469918176385, seed)
    println ulid.String(made.id)
    part := ulid.Entropy(made.id)
    defer part.free()
    println hex(part)
end
Output16 01563df36481d6764c61efb99302bd5b true 01ARYZ6S41TSV4RRFFQ69G5FAV 01ARYZ6S41001GC28C1W91A60V 000306090c0f1215181b

What people get wrong:

  • Expecting NewAt to be ordered inside one millisecond. It keeps no state; use a Generator.
  • Treating the time as secret. The first 10 characters are the creation time, readable by anyone who sees the id.
  • Comparing text with lowercase or aliases without Parse: 01arz and 01ARZ are the same id but different strings.
  • Forgetting to Free a generator or to free the vectors of Bytes, Entropy and Batch.
  • Comparing ids made by different generators or machines for strict order: clocks differ, so only ids of one generator are strictly ordered.

Types

ULID

struct ULID
A 128 bit identifier: a 48 bit millisecond timestamp and 80 random bits. It is a plain value, copy it freely. Ids compare in the same order as their times.
NameTypeDescription
timei64 = 0The timestamp in milliseconds since the Unix epoch.
hii64 = 0The upper 40 bits of the 80 random bits.
loi64 = 0The lower 40 bits of the 80 random bits.
encoding-ulid-Bytes.salam
import encoding.ulid

func main:
    r := ulid.Parse("01ARYZ6S41TSV4RRFFQ69G5FAV")
    mut raw := ulid.Bytes(r.id)
    defer raw.free()
    println raw.Len(), raw.get(0), raw.get(15)
    back := ulid.FromBytes(raw)
    println back.ok, ulid.Equal(back.id, r.id)
    mut wire := ulid.ToUUIDBytes(r.id)
    defer wire.free()
    println wire.Len(), ulid.Equal(ulid.FromUUIDBytes(wire).id, r.id)
    mut tail := ulid.Entropy(r.id)
    defer tail.free()
    println tail.Len(), r.id.hi, r.id.lo
    mut short := Vector {} as Vector<u8>
    defer short.free()
    short.push(1 as u8)
    println ulid.FromBytes(short).err == ulid.ERR_BYTES
end
Output16 1 91 true true 16 true 10 921107718639 797035380059 true

Result

struct Result
What parsing and the generators return: ok, the id and an err code.
NameTypeDescription
okbool = falseTrue when the operation worked.
idULIDThe id; the zero id when ok is false.
errint = 0One of the error codes, OK on success.
encoding-ulid-Parse.salam
import encoding.ulid

func main:
    r := ulid.Parse("01arYz6s41TsV4RrffQ69g5fav")
    println r.ok, ulid.Time(r.id), ulid.String(r.id)
    bad := ulid.Parse("01ARYZ6S41TSV4RRFFQ69G5FAU")
    println bad.ok, bad.err == ulid.ERR_CHAR
    println ulid.ParseStrict("01arYz6s41TsV4RrffQ69g5fav").ok
    println ulid.IsValid("7ZZZZZZZZZZZZZZZZZZZZZZZZZ"), ulid.IsValid("8ZZZZZZZZZZZZZZZZZZZZZZZZZ")
end
Outputtrue 1469918176385 01ARYZ6S41TSV4RRFFQ69G5FAV false true false true false

Generator

struct Generator
A monotonic generator. It owns a lock and its last id, so the copies of one Generator share state and any number of threads may call it. Release it with Free.
NameTypeDescription
statei64*The shared last timestamp and random parts, behind the lock.
musync.MutexThe lock that guards the state.
clockfunc(): i64The function that returns the current time in milliseconds.
entropyfunc(): i64The function that returns 40 random bits, or a negative number when it fails.
encoding-ulid-Next.salam
import encoding.ulid

mut tick := 100 as i64

func clock(): i64:
    ret tick
end

func source(): i64:
    ret 1
end

func main:
    g := ulid.NewGeneratorWith((): ret clock() end, (): ret source() end)
    defer ulid.Free(g)
    first := ulid.Next(g)
    second := ulid.Next(g)
    println ulid.String(first.id)
    println ulid.String(second.id)
    println ulid.Less(first.id, second.id)
    forced := ulid.NextAt(g, 50)
    println ulid.Time(forced.id), ulid.Less(second.id, forced.id)
end
Output00000000340000000100000001 00000000340000000100000002 true 100 true

Constants and variables

MAX_TIME

const MAX_TIME: i64 = 281474976710655
The largest timestamp a ULID can hold, 281474976710655 milliseconds (48 bits), which is the year 10889.
encoding-ulid-Errors.salam
import encoding.ulid

func main:
    each code in [ulid.OK, ulid.ERR_LENGTH, ulid.ERR_CHAR, ulid.ERR_OVERFLOW, ulid.ERR_TIME, ulid.ERR_ENTROPY, ulid.ERR_BYTES, 99]:
        println code, ulid.ErrorText(code)
    end
    r := ulid.Parse("short")
    println r.ok, r.err, ulid.IsZero(r.id)
    println ulid.MAX_TIME
    top := ulid.MaxAt(ulid.MAX_TIME)
    println top.time, top.hi, top.lo
end
Output0 ok 1 a ULID is 26 characters 2 invalid character in ULID 3 ULID value is larger than 7ZZZZZZZZZZZZZZZZZZZZZZZZZ 4 timestamp is outside 0 to 281474976710655 5 the entropy source failed 6 wrong number of bytes 99 unknown error false 1 true 281474976710655 281474976710655 1099511627775 1099511627775

OK

const OK: i32 = 0
Error code 0: nothing went wrong.

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

ERR_LENGTH

const ERR_LENGTH: i32 = 1
The text is not 26 characters long.

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

ERR_CHAR

const ERR_CHAR: i32 = 2
The text has a character outside the Crockford alphabet, such as U.

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

ERR_OVERFLOW

const ERR_OVERFLOW: i32 = 3
The value is larger than 7ZZZZZZZZZZZZZZZZZZZZZZZZZ (first character above 7), or an increment would overflow the 80 random bits.

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

ERR_TIME

const ERR_TIME: i32 = 4
The timestamp is outside 0 to MAX_TIME.

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

ERR_ENTROPY

const ERR_ENTROPY: i32 = 5
The entropy source reported a failure; no id was made and the generator state did not change.

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

ERR_BYTES

const ERR_BYTES: i32 = 6
A byte list had the wrong length (16 for FromBytes, 10 for FromParts).

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

Functions

FromParts

func FromParts(ms: i64, entropy: Vector<u8>): Result
Builds an id from a timestamp and exactly 10 entropy bytes, with no randomness, so tests can know every character.
encoding-ulid-FromParts.salam
import encoding.ulid

func main:
    mut seed := Vector {} as Vector<u8>
    defer seed.free()
    repeat 10 in i:
        seed.push((i + 1) as u8)
    end
    r := ulid.FromParts(1469918176385, seed)
    println r.ok, ulid.String(r.id)
    println ulid.FromParts(-1, seed).ok, ulid.FromParts(ulid.MAX_TIME + 1, seed).ok
    println ulid.String(ulid.FromParts(ulid.MAX_TIME, seed).id)
end
Outputtrue 01ARYZ6S41041061050R3GG28A false false 7ZZZZZZZZZ041061050R3GG28A

FromBytes

func FromBytes(b: Vector<u8>): Result
Reads the 16 byte binary form (6 bytes of time, 10 of randomness, big endian).

The example for this item is shown with the ones above: encoding-ulid-Bytes.salam

FromUUIDBytes

func FromUUIDBytes(b: Vector<u8>): Result
The same as FromBytes: a ULID fits the 16 bytes of a UUID.

The example for this item is shown with the ones above: encoding-ulid-Bytes.salam

String

func String(id: ULID): str
The 26 character canonical text, uppercase Crockford base32.
encoding-ulid-New.salam
import encoding.ulid

func main:
    a := ulid.New()
    b := ulid.NewString()
    println ulid.String(a).Len(), b.Len()
    println ulid.Less(a, ulid.Parse(b).id)
    at := ulid.NewAt(1469918176385)
    println at.ok, ulid.Time(at.id), at.id.time
    println ulid.NewAt(ulid.MAX_TIME + 1).err == ulid.ERR_TIME
    println ulid.Now() > 1700000000000
    last := ulid.Last(ulid.Default())
    println last.ok, ulid.Less(a, last.id)
    fresh := ulid.NewGenerator()
    defer ulid.Free(fresh)
    println ulid.Last(fresh).err == ulid.ERR_TIME
end
Output26 26 true true 1469918176385 1469918176385 true true true true true

Bytes

func Bytes(id: ULID): Vector<u8>
The 16 byte binary form. Free the vector.

The example for this item is shown with the ones above: encoding-ulid-Bytes.salam

ToUUIDBytes

func ToUUIDBytes(id: ULID): Vector<u8>
The same 16 bytes, for code that stores or sends them as a UUID.

The example for this item is shown with the ones above: encoding-ulid-Bytes.salam

Entropy

func Entropy(id: ULID): Vector<u8>
The 10 random bytes. Free the vector.

The example for this item is shown with the ones above: encoding-ulid-Bytes.salam

Time

func Time(id: ULID): i64
The timestamp in milliseconds.

The example for this item is shown with the ones above: encoding-ulid-New.salam

Compare

func Compare(a: ULID, b: ULID): int
-1, 0 or 1 by time first, then by the random part.
encoding-ulid-Compare.salam
import encoding.ulid

func main:
    early := ulid.MinAt(1000)
    late := ulid.MaxAt(1000)
    println ulid.Compare(early, late), ulid.Compare(late, early), ulid.Compare(early, early)
    println ulid.String(early)
    println ulid.String(late)
    println ulid.IsZero(ulid.MinAt(0)), ulid.IsZero(early)
    step := ulid.Increment(early)
    println ulid.String(step.id)
    println ulid.Increment(late).ok
end
Output-1 1 0 00000000Z80000000000000000 00000000Z8ZZZZZZZZZZZZZZZZ true false 00000000Z80000000000000001 false

Equal

func Equal(a: ULID, b: ULID): bool
True when two ids are the same.

The example for this item is shown with the ones above: encoding-ulid-Bytes.salam

Less

func Less(a: ULID, b: ULID): bool
True when the first id is older than the second, or smaller in the random part at the same time.

The example for this item is shown with the ones above: encoding-ulid-Next.salam

IsZero

func IsZero(id: ULID): bool
True for the all zero id.

The example for this item is shown with the ones above: encoding-ulid-Compare.salam

MinAt

func MinAt(ms: i64): ULID
The smallest id of a millisecond (random part all zero). Use it as the lower bound of a range query. The time is clamped to 0 to MAX_TIME.

The example for this item is shown with the ones above: encoding-ulid-Compare.salam

MaxAt

func MaxAt(ms: i64): ULID
The largest id of a millisecond (random part all ones), the upper bound of a range query.

The example for this item is shown with the ones above: encoding-ulid-Compare.salam

Increment

func Increment(id: ULID): Result
The id right after this one, with the random part grown by one. Fails with ERR_OVERFLOW when it is already all ones.

The example for this item is shown with the ones above: encoding-ulid-Compare.salam

Parse

func Parse(s: str): Result
Reads 26 characters. Lowercase is accepted, I and L mean 1, O means 0, U is refused, and a first character above 7 is ERR_OVERFLOW.

The example for this item is shown with the ones above: encoding-ulid-Parse.salam

ParseStrict

func ParseStrict(s: str): Result
Reads only the canonical form: uppercase, no aliases.

The example for this item is shown with the ones above: encoding-ulid-Parse.salam

ParseOr

func ParseOr(s: str, fallback: ULID): ULID
Parse, or the fallback id when the text is not valid.

The example for this item is shown with the ones above: encoding-ulid-Parse.salam

IsValid

func IsValid(s: str): bool
True when Parse accepts the text.

The example for this item is shown with the ones above: encoding-ulid-Parse.salam

NewGenerator

func NewGenerator(): Generator
A generator with the system clock and the operating system random source.

The example for this item is shown with the ones above: encoding-ulid-New.salam

NewGeneratorWith

func NewGeneratorWith(clock: func(): i64, entropy: func(): i64): Generator
A generator with your own clock and entropy functions, for tests and for sources that can fail. The entropy function returns 40 random bits (0 to 1099511627775) or a negative number on failure, which makes Next report ERR_ENTROPY.

The example for this item is shown with the ones above: encoding-ulid-Next.salam

Next

func Next(g: Generator): Result
The next id of a generator. In a new millisecond the random part is fresh; in the same millisecond, or when the clock went back, the previous random part grows by one. If the 80 bits run out the timestamp moves one millisecond ahead. Safe from many threads.

The example for this item is shown with the ones above: encoding-ulid-Next.salam

NextAt

func NextAt(g: Generator, ms: i64): Result
Like Next with the time given instead of read from the clock. A time before the last id keeps the last timestamp.

The example for this item is shown with the ones above: encoding-ulid-Next.salam

Batch

func Batch(g: Generator, n: int): Vector<ULID>
Makes n ids under one lock with one clock read. A failing entropy source ends the batch early, so check the length. Free the vector.
encoding-ulid-Batch.salam
import encoding.ulid

func main:
    ids := ulid.NewBatch(5)
    defer ids.free()
    mut increasing := ids.Len() == 5
    repeat ids.Len() - 1 in i:
        if not ulid.Less(ids.get(i), ids.get(i + 1)):
            increasing = false
        end
    end
    println ids.Len(), increasing
end
Output5 true

Last

func Last(g: Generator): Result
The last id the generator made, or ERR_TIME when it has made none yet.

The example for this item is shown with the ones above: encoding-ulid-New.salam

Free

func Free(g: Generator)
Releases a generator made by NewGenerator or NewGeneratorWith.

The example for this item is shown with the ones above: encoding-ulid-Next.salam

Default

func Default(): Generator
The process wide generator behind New, NewString and NewBatch. Do not free it.

The example for this item is shown with the ones above: encoding-ulid-New.salam

New

func New(): ULID
A new id from the default generator, using the system clock and the operating system random source. Ids from one process are strictly increasing, even from many threads at once.

The example for this item is shown with the ones above: encoding-ulid-New.salam

NewString

func NewString(): str
Shorthand for String(New()).

The example for this item is shown with the ones above: encoding-ulid-New.salam

NewAt

func NewAt(ms: i64): Result
An id for a chosen millisecond with fresh random bits. It keeps no state, so two calls in one millisecond are not ordered; use a Generator when order matters. Fails with ERR_TIME outside 0 to MAX_TIME.

The example for this item is shown with the ones above: encoding-ulid-New.salam

NewBatch

func NewBatch(n: int): Vector<ULID>
Makes n ids from the default generator under one lock, so they are consecutive and increasing. Free the vector.

The example for this item is shown with the ones above: encoding-ulid-Batch.salam

ErrorText

func ErrorText(code: int): str
A short English message for an error code.

The example for this item is shown with the ones above: encoding-ulid-Errors.salam

Now

func Now(): i64
The system clock in milliseconds since the Unix epoch, kept inside 0 to MAX_TIME.

The example for this item is shown with the ones above: encoding-ulid-New.salam