From: Jérôme Benoit Date: Mon, 24 Oct 2022 11:42:54 +0000 (+0200) Subject: Fix random integer generator X-Git-Tag: v2.3.8~115 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b1620ccf72bc772e9d0542da28dcff9e52b4174a;p=poolifier.git Fix random integer generator Signed-off-by: Jérôme Benoit --- 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 }