From b1620ccf72bc772e9d0542da28dcff9e52b4174a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Oct 2022 13:42:54 +0200 Subject: [PATCH] Fix random integer generator MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmarks/benchmarks-utils.js | 2 +- benchmarks/worker-selection/lru.js | 2 +- tests/test-utils.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.js index 62613c7e..8bd137a3 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -32,7 +32,7 @@ function jsonIntegerSerialization (n) { function generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { max = Math.floor(max) - if (min) { + if (min != null || min !== 0) { min = Math.ceil(min) return Math.floor(Math.random() * (max - min + 1)) + min } diff --git a/benchmarks/worker-selection/lru.js b/benchmarks/worker-selection/lru.js index 90628d3a..a4b2c69a 100644 --- a/benchmarks/worker-selection/lru.js +++ b/benchmarks/worker-selection/lru.js @@ -50,7 +50,7 @@ const defaultPivotIndexSelect = (leftIndex, rightIndex) => { } const randomPivotIndexSelect = (leftIndex, rightIndex) => { - return generateRandomInteger(leftIndex, rightIndex) + return generateRandomInteger(rightIndex, leftIndex) } function swap (array, index1, index2) { diff --git a/tests/test-utils.js b/tests/test-utils.js index 9a49c822..76db3557 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -38,7 +38,7 @@ class TestUtils { static generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { max = Math.floor(max) - if (min) { + if (min != null || min !== 0) { min = Math.ceil(min) return Math.floor(Math.random() * (max - min + 1)) + min } -- 2.34.1