Skip to content

Commit

Permalink
revert(generation): use crypto.randomUUID for rand_b
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Apr 26, 2024
1 parent 9208995 commit 0bb0e75
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ function addHyphens(id: string) {

// Generates the 62 bits [rand_b] part in bigint format.
function genRandB() {
// Generate random 64 bits and convert them to hex.
const hex = Array.from(crypto.getRandomValues(new Uint8Array(8)))
.map((i) => i.toString(16).padStart(2, "0"))
.join("");

const hex = crypto.randomUUID().replace(/-/g, "");
const mask = (1n << 62n) - 1n;
return BigInt("0x" + hex) & mask;
}
Expand Down

0 comments on commit 0bb0e75

Please sign in to comment.