We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6b2286 commit a12d92cCopy full SHA for a12d92c
2 files changed
lib/internal/crypto/random.js
@@ -149,8 +149,8 @@ function randomInt(min, max, callback) {
149
if (!NumberIsSafeInteger(max)) {
150
throw new ERR_INVALID_ARG_TYPE('max', 'safe integer', max);
151
}
152
- if (!(max >= min)) {
153
- throw new ERR_OUT_OF_RANGE('max', `>= ${min}`, max);
+ if (max <= min) {
+ throw new ERR_OUT_OF_RANGE('max', `> ${min}`, max);
154
155
156
// First we generate a random int between [0..range)
test/parallel/test-crypto-random.js
@@ -456,13 +456,16 @@ assert.throws(
456
457
);
458
459
- crypto.randomInt(0, common.mustCall());
460
- crypto.randomInt(0, 0, common.mustCall());
461
- assert.throws(() => crypto.randomInt(-1, common.mustNotCall()), {
462
- code: 'ERR_OUT_OF_RANGE',
463
- name: 'RangeError',
464
- message: 'The value of "max" is out of range. It must be >= 0. Received -1'
465
- });
+ crypto.randomInt(1, common.mustCall());
+ crypto.randomInt(0, 1, common.mustCall());
+ for (const arg of [[0], [1, 1], [3, 2], [-5, -5], [11, -10]]) {
+ assert.throws(() => crypto.randomInt(...arg, common.mustNotCall()), {
+ code: 'ERR_OUT_OF_RANGE',
+ name: 'RangeError',
+ message: 'The value of "max" is out of range. It must be > ' +
466
+ `${arg[arg.length - 2] || 0}. Received ${arg[arg.length - 1]}`
467
+ });
468
+ }
469
470
const MAX_RANGE = 0xFFFF_FFFF_FFFF;
471
crypto.randomInt(MAX_RANGE, common.mustCall());
0 commit comments