Closed fireflysemantics closed 1 year ago
The test is also "Random" in nature. If I run it 3 times in a row, 1 run will pass. The other two will have 1 or 2 random numbers with dashes in them.
It seems one possible solution is to use %
instead of /
:
I ran 10 million samples and non contain dashes.
Created an Angular Package Format version of cuid here:
https://www.npmjs.com/package/@fireflysemantics/cuid
This is primarily for the browser / typescript use case.
https://medium.com/@ole.ersoy/generating-collision-resistant-fast-unique-ids-d7a9d1286d9c
Please open a PR
Just change:
export function getRandomValue () {
return Math.abs(crypto.randomBytes(4)
.readInt32BE(0) / lim)
}
to:
export function getRandomValue () {
return Math.abs(crypto.randomBytes(4)
.readInt32BE(0) % lim)
}
Please reopen if this issue still exists.
I created this test:
For this conversion:
It does return a dashed random value: