MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / incrementRandom

Function incrementRandom

shared/src/binary.ts:54–63  ·  view source on GitHub ↗
(arr: Uint8Array)

Source from the content-addressed store, hash-verified

52}
53
54export function incrementRandom(arr: Uint8Array): void {
55 for (let i = idLength - 1; i >= epochLength; i--) {
56 if (arr[i]! < 255) {
57 arr[i]!++
58 return
59 }
60 arr[i] = 0
61 }
62 throw new Error('max random reached')
63}
64
65// inspired by https://github.com/ryan-mars/ulid-workers/blob/06689d9ddd894bfc608c6131f9bbd2a8b48bcbc8/src/ulid.ts#L147
66export function idFactory() {

Callers 2

binary.test.tsFile · 0.90
idFactoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected