Let random seed be a property
This commit is contained in:
parent
dbaffb373c
commit
23efa3df7f
1 changed files with 3 additions and 2 deletions
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
var random = { // eslint-disable-line no-unused-vars
|
var random = { // eslint-disable-line no-unused-vars
|
||||||
|
seed: null,
|
||||||
twister: null,
|
twister: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,10 +12,10 @@ var random = { // eslint-disable-line no-unused-vars
|
||||||
*/
|
*/
|
||||||
init: function (seed) {
|
init: function (seed) {
|
||||||
if (seed === null || seed === undefined) {
|
if (seed === null || seed === undefined) {
|
||||||
seed = new Date().getTime()
|
this.seed = new Date().getTime()
|
||||||
}
|
}
|
||||||
this.twister = new MersenneTwister()
|
this.twister = new MersenneTwister()
|
||||||
this.twister.seed(seed)
|
this.twister.seed(this.seed)
|
||||||
},
|
},
|
||||||
number: function (limit) {
|
number: function (limit) {
|
||||||
// Returns an integer in [0, limit). Uniform distribution.
|
// Returns an integer in [0, limit). Uniform distribution.
|
||||||
|
|
Loading…
Reference in a new issue