Let random seed be a property

This commit is contained in:
Christoph Diehl 2017-06-08 04:12:49 +02:00
parent dbaffb373c
commit 23efa3df7f

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var random = { // eslint-disable-line no-unused-vars
seed: null,
twister: null,
/**
@ -11,10 +12,10 @@ var random = { // eslint-disable-line no-unused-vars
*/
init: function (seed) {
if (seed === null || seed === undefined) {
seed = new Date().getTime()
this.seed = new Date().getTime()
}
this.twister = new MersenneTwister()
this.twister.seed(seed)
this.twister.seed(this.seed)
},
number: function (limit) {
// Returns an integer in [0, limit). Uniform distribution.