Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README: clarify monotonicity requirements #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ Crockford's Base32 is used as shown. This alphabet excludes the letters I, L, O,

### Monotonicity

When generating a ULID within the same millisecond, we can provide some
guarantees regarding sort order. Namely, if the same millisecond is detected, the `random` component is incremented by 1 bit in the least significant bit position (with carrying). For example:
When generating a ULID within the same millisecond, implementations may optionally provide monotonicity by statefully incrementing the `random` component rather than regenerating it.

```javascript
import { monotonicFactory } from 'ulid'
Expand All @@ -147,7 +146,7 @@ ulid() // 01BX5ZZKBKACTAV9WEVGEMMVRZ
ulid() // 01BX5ZZKBKACTAV9WEVGEMMVS0
```

If, in the extremely unlikely event that, you manage to generate more than 2<sup>80</sup> ULIDs within the same millisecond, or cause the random component to overflow with less, the generation will fail.
Generating more than 2<sup>80</sup> ULIDs within the same millisecond, or causing the random component to overflow, will result in an error.

```javascript
import { monotonicFactory } from 'ulid'
Expand Down