Skip to content

Commit

Permalink
use Math.log2 (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov authored Oct 28, 2024
1 parent d0548a4 commit d6f0d53
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export let customRandom = (alphabet, defaultSize, getRandom) => {
// `2^31 - 1` number, which exceeds the alphabet size.
// For example, the bitmask for the alphabet size 30 is 31 (00011111).
// `Math.clz32` is not used, because it is not available in browsers.
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
let mask = (2 << Math.log2(alphabet.length - 1)) - 1
// Though, the bitmask solution is not perfect since the bytes exceeding
// the alphabet size are refused. Therefore, to reliably generate the ID,
// the random bytes redundancy has to be satisfied.
Expand Down

0 comments on commit d6f0d53

Please sign in to comment.