type: 'conjunction'
})
-const 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(Math.random() * (max - min + 1)) + min
- }
- return Math.floor(Math.random() * (max + 1))
-}
-
const jsonIntegerSerialization = n => {
for (let i = 0; i < n; i++) {
const o = {
module.exports = {
LIST_FORMATTER,
executeTaskFunction,
- generateRandomInteger,
runPoolifierPoolBenchmark
}
+import { randomInt } from 'node:crypto'
import Benchmark from 'benchmark'
-import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.cjs'
+import { LIST_FORMATTER } from '../benchmarks-utils.cjs'
function generateRandomTasksMap (
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)
}
function swap (array, index1, index2) {
+import { randomInt } from 'node:crypto'
import { expect } from 'expect'
import { FixedThreadPool } from '../../../lib/index.cjs'
import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs'
-import { generateRandomInteger } from '../../test-utils.cjs'
describe('Weighted round robin strategy worker choice strategy test suite', () => {
// const min = 1
it('Verify that reset() resets internals', () => {
const strategy = new WeightedRoundRobinWorkerChoiceStrategy(pool)
- strategy.currentWorkerId = generateRandomInteger(Number.MAX_SAFE_INTEGER, 1)
- strategy.workerVirtualTaskRunTime = generateRandomInteger(
- Number.MAX_SAFE_INTEGER,
- 1
- )
+ strategy.currentWorkerId = randomInt(281474976710655)
+ strategy.workerVirtualTaskRunTime = randomInt(281474976710655)
expect(strategy.reset()).toBe(true)
expect(strategy.nextWorkerNodeKey).toBe(0)
expect(strategy.previousWorkerNodeKey).toBe(0)
})
}
-const 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(Math.random() * (max - min + 1)) + min
- }
- return Math.floor(Math.random() * (max + 1))
-}
-
const jsonIntegerSerialization = n => {
for (let i = 0; i < n; i++) {
const o = {
executeTaskFunction,
factorial,
fibonacci,
- generateRandomInteger,
jsonIntegerSerialization,
sleep,
sleepTaskFunction,