Minor fixes

This commit is contained in:
pyoor 2018-07-26 19:44:34 -04:00
parent 2786f886fc
commit e87962069a

View file

@ -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 * @param {number} limit
*/ */
static 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 () { static float () {
if (!random.twister) { 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} start
* @param {number} limit * @param {number} limit
*/ */
@ -61,15 +61,17 @@ class random {
if (!random.twister) { if (!random.twister) {
throw new Error('random.init must be called first.') throw new Error('random.init must be called first.')
} }
if (isNaN(start) || isNaN(limit)) { if (isNaN(start) || isNaN(limit)) {
logger.traceback() logger.traceback()
throw new TypeError(`random.range() received non-number type: (${start}, ${limit})`) throw new TypeError(`random.range() received non-number type: (${start}, ${limit})`)
} }
return random.number(limit - start + 1) + start 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 * @param {number} limit
*/ */
static ludOneTo (limit) { static ludOneTo (limit) {