build(deps-dev): apply updates
[benchmarks-js.git] / random.js
index 2bdd430aea2ad7461772e1592c94d8c3ad3ceafa..8c0fa86e669b384e4d812478e00b6a61716031c8 100644 (file)
--- 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)
+})