X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=random.js;h=f4fd9f0bd53f9182f13541be0b3bb17bc7c5e27c;hb=c4e74a3d1363652c56deccd9446f94d8df7a846e;hp=ee5cc617ed12a80050a62cb65a707bd8b2da4899;hpb=da504870febba0179ba92a342528d6f4384e9534;p=benchmarks-js.git diff --git a/random.js b/random.js index ee5cc61..f4fd9f0 100644 --- a/random.js +++ b/random.js @@ -9,6 +9,9 @@ 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 != null && min !== 0) { min = Math.ceil(min) @@ -23,6 +26,9 @@ 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 != null && min !== 0) { min = Math.ceil(min)