From e87962069a22a6b2ea6e4ae758297d7677439f7c Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 26 Jul 2018 19:44:34 -0400 Subject: [PATCH] Minor fixes --- lib/random/random.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/random/random.js b/lib/random/random.js index 38e1034..403a59a 100644 --- a/lib/random/random.js +++ b/lib/random/random.js @@ -20,7 +20,7 @@ class random { } /** - * Returns an integer in [0, limit] (uniform distribution) + * Returns an integer in [0, limit) (uniform distribution) * @param {number} limit */ static number (limit) { @@ -42,7 +42,7 @@ class random { } /** - * Returns a float in [0, 1] (uniform distribution) + * Returns a float in [0, 1) (uniform distribution) */ static float () { if (!random.twister) { @@ -53,7 +53,7 @@ class random { } /** - * Returns an integer in [start, limit] (uniform distribution) + * Returns an integer in [start, limit) (uniform distribution) * @param {number} start * @param {number} limit */ @@ -61,15 +61,17 @@ class random { if (!random.twister) { throw new Error('random.init must be called first.') } + if (isNaN(start) || isNaN(limit)) { logger.traceback() throw new TypeError(`random.range() received non-number type: (${start}, ${limit})`) } + return random.number(limit - start + 1) + start } /** - * Returns a float in [1, limit]. The logarithm has uniform distribution. + * Returns a float in [1, limit). The logarithm has uniform distribution. * @param {number} limit */ static ludOneTo (limit) {