Set default limit value

This commit is contained in:
pyoor 2018-08-27 18:57:39 -04:00
parent 942d9d89ba
commit ba33374c65

View file

@ -12,22 +12,18 @@ class random {
*/
static init (seed = new Date().getTime()) {
random.twister = new MersenneTwister()
random.twister.seed(random.seed)
random.twister.seed(seed)
}
/**
* Returns an integer in [0, limit) (uniform distribution)
* @param {number} limit
*/
static number (limit) {
static number (limit = 0xffffffff) {
if (!random.twister) {
throw new Error('random.init must be called first.')
}
if (limit === null || limit === undefined) {
limit = 0xffffffff
}
let x = (0x100000000 / limit) >>> 0
let y = (x * limit) >>> 0
let r