X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=random.js;h=8c0fa86e669b384e4d812478e00b6a61716031c8;hb=52d07fb863422041a24874efb893c711bf0b9cd4;hp=2bdd430aea2ad7461772e1592c94d8c3ad3ceafa;hpb=99d76a65d58d151b760876e1e8e9178be3624365;p=benchmarks-js.git diff --git a/random.js b/random.js index 2bdd430..8c0fa86 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) @@ -95,4 +100,6 @@ Benchmark.suite( format: 'table.html', details: true }) -) +).catch(err => { + console.error(err) +})