X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=random.js;h=c3e5c4a8383c3821c223c40921a95ea63da8bb3e;hb=faa41c13d358122e12d3bf111335441b3b56c375;hp=2bdd430aea2ad7461772e1592c94d8c3ad3ceafa;hpb=99d76a65d58d151b760876e1e8e9178be3624365;p=benchmarks-js.git diff --git a/random.js b/random.js index 2bdd430..c3e5c4a 100644 --- a/random.js +++ b/random.js @@ -1,11 +1,11 @@ +const crypto = require('crypto') const Benchmark = require('benny') const { secureRandom, secureRandomWithRandomValues } = 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 != null && 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)