Set default limit value
This commit is contained in:
parent
942d9d89ba
commit
ba33374c65
1 changed files with 2 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue