From d6f0d5335150332599483b60185cfe8462fa5286 Mon Sep 17 00:00:00 2001 From: Kirill Groshkov Date: Mon, 28 Oct 2024 12:24:10 +0100 Subject: [PATCH] use Math.log2 (#504) --- index.browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.browser.js b/index.browser.js index 8b51358c..9ec0a948 100644 --- a/index.browser.js +++ b/index.browser.js @@ -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.