-import { randomBytes, getRandomValues } from 'node:crypto'
+import { randomBytes, getRandomValues, randomInt } from 'node:crypto'
/**
* Generate a cryptographically secure random number in the [0,1[ range
return getRandomValues(new Uint32Array(1))[0] / 0x100000000
}
-/**
- * @param max
- * @param min
- * @returns
- */
-export function generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
- if (max < min || max < 0 || min < 0) {
- throw new RangeError('Invalid interval')
- }
- max = Math.floor(max)
- if (min != null && min !== 0) {
- min = Math.ceil(min)
- return Math.floor(secureRandom() * (max - min + 1)) + min
- }
- return Math.floor(secureRandom() * (max + 1))
-}
-
/**
*
* @param max
numberMax = Number.MAX_VALUE,
numberGenerator = generateRandomFloat
) {
- const size = generateRandomInteger(sizeMax)
+ const size = randomInt(sizeMax)
const object = {}
for (let i = 0; i < size; i++) {
object[i.toString()] = numberGenerator(numberMax)
+import { randomInt } from 'node:crypto'
import Benchmark from 'benny'
-import { generateRandomInteger } from './benchmark-utils.mjs'
/**
* @param numberOfWorkers
) {
const tasksArray = []
for (let i = 0; i < numberOfWorkers; i++) {
- const task = [i, generateRandomInteger(maxNumberOfTasksPerWorker)]
+ const task = [i, randomInt(maxNumberOfTasksPerWorker)]
tasksArray.push(task)
}
return new Map(tasksArray)
}
const randomPivotIndexSelect = (leftIndex, rightIndex) => {
- return generateRandomInteger(rightIndex, leftIndex)
+ return randomInt(leftIndex, rightIndex)
}
/**