Apply dependencies update
[benchmarks-js.git] / random.js
index ed5acd6843685ecd54fe66855b659de6e31a3dfe..f4fd9f0bd53f9182f13541be0b3bb17bc7c5e27c 100644 (file)
--- a/random.js
+++ b/random.js
@@ -9,8 +9,11 @@ const maximum = Number.MAX_SAFE_INTEGER
  * @returns
  */
 function getSecureRandomInteger (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) {
+  if (min != null && min !== 0) {
     min = Math.ceil(min)
     return Math.floor(secureRandom() * (max - min + 1)) + min
   }
@@ -23,8 +26,11 @@ function getSecureRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
  * @returns
  */
 function getRandomInteger (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) {
+  if (min != null && min !== 0) {
     min = Math.ceil(min)
     return Math.floor(Math.random() * (max - min + 1)) + min
   }