From 4cc567bb3a9f229d3f54cd8146d0aea298f508ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 10 Jan 2024 13:48:46 +0100 Subject: [PATCH] refactor: cleanup unneeded condition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- random.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/random.mjs b/random.mjs index 16037df..f01ab2b 100644 --- a/random.mjs +++ b/random.mjs @@ -17,7 +17,7 @@ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { throw new RangeError('Invalid interval') } max = Math.floor(max) - if (min != null && min !== 0) { + if (min !== 0) { min = Math.ceil(min) return Math.floor(secureRandom() * (max - min + 1)) + min } @@ -37,7 +37,7 @@ function getSecureRandomIntegerWithRandomValues ( throw new RangeError('Invalid interval') } max = Math.floor(max) - if (min != null && min !== 0) { + if (min !== 0) { min = Math.ceil(min) return Math.floor(secureRandomWithRandomValues() * (max - min + 1)) + min } @@ -54,7 +54,7 @@ function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { throw new RangeError('Invalid interval') } max = Math.floor(max) - if (min != null && min !== 0) { + if (min !== 0) { min = Math.ceil(min) return Math.floor(Math.random() * (max - min + 1)) + min } @@ -74,7 +74,7 @@ Benchmark.suite( ), Benchmark.add('Crypto random integer generator', (max = maximum, min = 0) => { max = Math.floor(max) - if (min != null && min !== 0) { + if (min !== 0) { min = Math.ceil(min) return Math.floor(randomInt(min, max + 1)) } -- 2.34.1