Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ function randomInt(min, max, cb) {
if (!NumberIsSafeInteger(max)) {
throw new ERR_INVALID_ARG_TYPE('max', 'safe integer', max);
}
if (!(max >= min)) {
throw new ERR_OUT_OF_RANGE('max', `>= ${min}`, max);
if (max <= min) {
throw new ERR_OUT_OF_RANGE('max', `> ${min}`, max);
}

// First we generate a random int between [0..range)
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,12 @@ assert.throws(
}
);

crypto.randomInt(0, common.mustCall());
crypto.randomInt(0, 0, common.mustCall());
Comment thread
tniessen marked this conversation as resolved.
Resolved
assert.throws(() => crypto.randomInt(-1, common.mustNotCall()), {
crypto.randomInt(1, common.mustCall());
crypto.randomInt(0, 1, common.mustCall());
assert.throws(() => crypto.randomInt(0, common.mustNotCall()), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "max" is out of range. It must be >= 0. Received -1'
message: 'The value of "max" is out of range. It must be > 0. Received 0'
});

const MAX_RANGE = 0xFFFF_FFFF_FFFF;
Expand Down