UlidFactory class
Generates Ulid instances.
By default every next call draws a fresh 80-bit random value. With
monotonic set, a call whose timestamp does not exceed the last one
(same millisecond, or the clock went backwards) reuses the last
timestamp and increments the last random value instead, so IDs from
this factory always sort in call order (see the
ULID spec's monotonicity recommendation).
monotonicRandomBits keeps that many least-significant bits genuinely
random on every call instead of incrementing them; only the remaining,
most-significant 80 - N bits act as the counter. Ordering is
unaffected, but a bigger tail means a smaller, sooner-overflowing
counter. monotonicBufferBits clears that many most-significant bits
of every freshly drawn random value, guaranteeing the counter that
amount of headroom before it can overflow (1 guarantees at least half
of the counter's range is free; this is the usual practical setting).
Counter overflow throws a StateError by default; set
incrementMillisOnOverflow to advance the timestamp by 1ms and draw a
fresh random value instead.
A single UlidFactory instance is not safe to share across isolates, but is safe to reuse across calls within the same isolate.
Constructors
- UlidFactory({bool monotonic = false, bool incrementMillisOnOverflow = false, int monotonicRandomBits = 0, int monotonicBufferBits = 0, Random? random})
- Creates a new UlidFactory.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
next(
{int? millis}) → Ulid - Creates a new Ulid instance.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited