From: Jérôme Benoit Date: Sun, 22 Jan 2023 19:03:45 +0000 (+0100) Subject: Benchmark inclusive interval crypto.randomInt based integer generator X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=804a63757c95b0f5b802233ba678cac3d1a7a886;p=benchmarks-js.git Benchmark inclusive interval crypto.randomInt based integer generator Signed-off-by: Jérôme Benoit --- diff --git a/random.js b/random.js index 2bdd430..272d8e6 100644 --- a/random.js +++ b/random.js @@ -5,7 +5,7 @@ const { } = require('./benchmark-utils') const crypto = require('crypto') -const maximum = 281474976710655 +const maximum = 281474976710654 /** * @param max @@ -72,8 +72,13 @@ Benchmark.suite( getSecureRandomIntegerWithRandomValues(maximum) } ), - Benchmark.add('Crypto random integer generator', () => { - crypto.randomInt(maximum) + Benchmark.add('Crypto random integer generator', (max = maximum, min = 0) => { + max = Math.floor(max) + if (min !== undefined && min !== 0) { + min = Math.ceil(min) + return Math.floor(crypto.randomInt(min, max + 1)) + } + return Math.floor(crypto.randomInt(max + 1)) }), Benchmark.add('Math random integer generator', () => { getRandomInteger(maximum)