From 57f4392ac07d8a348e80ecd5b18b0331236034d8 Mon Sep 17 00:00:00 2001 From: svanstone-resilient <62011179+svanstone-resilient@users.noreply.github.com> Date: Mon, 7 Feb 2022 11:06:49 +0000 Subject: [PATCH] getRandomValue() should not be able to return 1 exactly Math.random returns from 0 to 1 but shouldn't be able to return 1 exactly. (And this is a crypto replacement for Math.random) --- lib/getRandomValue.browser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/getRandomValue.browser.js b/lib/getRandomValue.browser.js index bb74de4..43f2680 100644 --- a/lib/getRandomValue.browser.js +++ b/lib/getRandomValue.browser.js @@ -7,9 +7,9 @@ var crypto = typeof window !== 'undefined' && self.crypto; if (crypto) { - var lim = Math.pow(2, 32) - 1; + var lim = Math.pow(2, 32); getRandomValue = function () { - return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0] / lim); + return crypto.getRandomValues(new Uint32Array(1))[0] / lim; }; } else { getRandomValue = Math.random;