@@ -320,10 +320,10 @@ assert.throws(
320
320
{
321
321
const randomInts = [ ] ;
322
322
for ( let i = 0 ; i < 100 ; i ++ ) {
323
- crypto . randomInt ( 1 , 4 , common . mustCall ( ( err , n ) => {
323
+ crypto . randomInt ( 1 , 3 , common . mustCall ( ( err , n ) => {
324
324
assert . ifError ( err ) ;
325
325
assert . ok ( n >= 1 ) ;
326
- assert . ok ( n < 4 ) ;
326
+ assert . ok ( n <= 3 ) ;
327
327
randomInts . push ( n ) ;
328
328
if ( randomInts . length === 100 ) {
329
329
assert . ok ( ! randomInts . includes ( 0 ) ) ;
@@ -338,10 +338,10 @@ assert.throws(
338
338
{
339
339
const randomInts = [ ] ;
340
340
for ( let i = 0 ; i < 100 ; i ++ ) {
341
- crypto . randomInt ( - 10 , - 7 , common . mustCall ( ( err , n ) => {
341
+ crypto . randomInt ( - 10 , - 8 , common . mustCall ( ( err , n ) => {
342
342
assert . ifError ( err ) ;
343
343
assert . ok ( n >= - 10 ) ;
344
- assert . ok ( n < - 7 ) ;
344
+ assert . ok ( n <= - 8 ) ;
345
345
randomInts . push ( n ) ;
346
346
if ( randomInts . length === 100 ) {
347
347
assert . ok ( ! randomInts . includes ( - 11 ) ) ;
@@ -359,12 +359,15 @@ assert.throws(
359
359
crypto . randomInt ( 3 , common . mustCall ( ( err , n ) => {
360
360
assert . ifError ( err ) ;
361
361
assert . ok ( n >= 0 ) ;
362
- assert . ok ( n < 3 ) ;
362
+ assert . ok ( n <= 3 ) ;
363
363
randomInts . push ( n ) ;
364
364
if ( randomInts . length === 100 ) {
365
+ assert . ok ( ! randomInts . includes ( - 1 ) ) ;
365
366
assert . ok ( randomInts . includes ( 0 ) ) ;
366
367
assert . ok ( randomInts . includes ( 1 ) ) ;
367
368
assert . ok ( randomInts . includes ( 2 ) ) ;
369
+ assert . ok ( randomInts . includes ( 3 ) ) ;
370
+ assert . ok ( ! randomInts . includes ( 4 ) ) ;
368
371
}
369
372
} ) ) ;
370
373
}
@@ -375,21 +378,24 @@ assert.throws(
375
378
for ( let i = 0 ; i < 100 ; i ++ ) {
376
379
const n = crypto . randomInt ( 3 ) ;
377
380
assert . ok ( n >= 0 ) ;
378
- assert . ok ( n < 3 ) ;
381
+ assert . ok ( n <= 3 ) ;
379
382
randomInts . push ( n ) ;
380
383
}
381
384
385
+ assert . ok ( ! randomInts . includes ( - 1 ) ) ;
382
386
assert . ok ( randomInts . includes ( 0 ) ) ;
383
387
assert . ok ( randomInts . includes ( 1 ) ) ;
384
388
assert . ok ( randomInts . includes ( 2 ) ) ;
389
+ assert . ok ( randomInts . includes ( 3 ) ) ;
390
+ assert . ok ( ! randomInts . includes ( 4 ) ) ;
385
391
}
386
392
{
387
393
// Synchronous API with min
388
394
const randomInts = [ ] ;
389
395
for ( let i = 0 ; i < 100 ; i ++ ) {
390
- const n = crypto . randomInt ( 3 , 6 ) ;
396
+ const n = crypto . randomInt ( 3 , 5 ) ;
391
397
assert . ok ( n >= 3 ) ;
392
- assert . ok ( n < 6 ) ;
398
+ assert . ok ( n <= 5 ) ;
393
399
randomInts . push ( n ) ;
394
400
}
395
401
@@ -403,25 +409,46 @@ assert.throws(
403
409
assert . throws ( ( ) => crypto . randomInt ( i , 100 , common . mustNotCall ( ) ) , {
404
410
code : 'ERR_INVALID_ARG_TYPE' ,
405
411
name : 'TypeError' ,
406
- message : 'The "min" argument must be integer.' +
412
+ message : 'The "min" argument must be safe integer.' +
407
413
`${ common . invalidArgTypeHelper ( i ) } ` ,
408
414
} ) ;
409
415
410
416
assert . throws ( ( ) => crypto . randomInt ( 0 , i , common . mustNotCall ( ) ) , {
411
417
code : 'ERR_INVALID_ARG_TYPE' ,
412
418
name : 'TypeError' ,
413
- message : 'The "max" argument must be integer.' +
419
+ message : 'The "max" argument must be safe integer.' +
414
420
`${ common . invalidArgTypeHelper ( i ) } ` ,
415
421
} ) ;
416
422
417
423
assert . throws ( ( ) => crypto . randomInt ( i , common . mustNotCall ( ) ) , {
418
424
code : 'ERR_INVALID_ARG_TYPE' ,
419
425
name : 'TypeError' ,
420
- message : 'The "max" argument must be integer.' +
426
+ message : 'The "max" argument must be safe integer.' +
421
427
`${ common . invalidArgTypeHelper ( i ) } ` ,
422
428
} ) ;
423
429
} ) ;
424
430
431
+ const minInt = Number . MIN_SAFE_INTEGER ;
432
+ const maxInt = Number . MAX_SAFE_INTEGER ;
433
+
434
+ crypto . randomInt ( minInt , minInt + 5 , common . mustCall ( ) ) ;
435
+ crypto . randomInt ( maxInt - 5 , maxInt , common . mustCall ( ) ) ;
436
+
437
+ assert . throws ( ( ) => crypto . randomInt ( minInt - 1 , minInt + 5 , common . mustNotCall ( ) ) , {
438
+ code : 'ERR_INVALID_ARG_TYPE' ,
439
+ name : 'TypeError' ,
440
+ message : 'The "min" argument must be safe integer.' +
441
+ `${ common . invalidArgTypeHelper ( minInt - 1 ) } ` ,
442
+ } ) ;
443
+
444
+ assert . throws ( ( ) => crypto . randomInt ( maxInt - 5 , maxInt + 1 , common . mustNotCall ( ) ) , {
445
+ code : 'ERR_INVALID_ARG_TYPE' ,
446
+ name : 'TypeError' ,
447
+ message : 'The "max" argument must be safe integer.' +
448
+ `${ common . invalidArgTypeHelper ( maxInt + 1 ) } ` ,
449
+ } ) ;
450
+
451
+
425
452
assert . throws ( ( ) => crypto . randomInt ( 0 , 0 , common . mustNotCall ( ) ) , {
426
453
code : 'ERR_OUT_OF_RANGE' ,
427
454
name : 'RangeError' ,
@@ -445,7 +472,7 @@ assert.throws(
445
472
name : 'RangeError' ,
446
473
message : 'The value of "max - min" is out of range. ' +
447
474
`It must be <= ${ ( 2 ** 48 ) - 1 } . ` +
448
- 'Received 281_474_976_710_656 '
475
+ 'Received 281_474_976_710_657 '
449
476
} ) ;
450
477
451
478
[ 1 , true , NaN , null , { } , [ ] ] . forEach ( ( i ) => {
0 commit comments