1eeeedd362d90903caab90e567ab79d69b2bf68a
1 const Benchmark
= require('benny')
2 const { secureRandom
} = require('./benchmark-utils')
4 const maximum
= Number
.MAX_SAFE_INTEGER
11 function getSecureRandomInteger (max
= Number
.MAX_SAFE_INTEGER
, min
= 0) {
15 return Math
.floor(secureRandom() * (max
- min
+ 1)) + min
17 return Math
.floor(secureRandom() * (max
+ 1))
25 function getRandomInteger (max
= Number
.MAX_SAFE_INTEGER
, min
= 0) {
29 return Math
.floor(Math
.random() * (max
- min
+ 1)) + min
31 return Math
.floor(Math
.random() * (max
+ 1))
35 'Random Integer Generator',
36 Benchmark
.add('Secure random integer generator', function () {
37 getSecureRandomInteger(maximum
)
39 Benchmark
.add('Random integer generator', function () {
40 getRandomInteger(maximum
)
45 file
: 'random-integer-generator',
50 file
: 'random-integer-generator',
55 file
: 'random-integer-generator',