mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Fix RandomDataGenerator's randomness
This commit is contained in:
parent
1f8d0c80f9
commit
fc1181970b
1 changed files with 17 additions and 3 deletions
|
@ -67,6 +67,17 @@ var RandomDataGenerator = new Class({
|
|||
*/
|
||||
this.s2 = 0;
|
||||
|
||||
/**
|
||||
* Internal var.
|
||||
*
|
||||
* @name Phaser.Math.RandomDataGenerator#n
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.n = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
|
@ -117,7 +128,7 @@ var RandomDataGenerator = new Class({
|
|||
hash: function (data)
|
||||
{
|
||||
var h;
|
||||
var n = 0xefc8249d;
|
||||
var n = this.n;
|
||||
|
||||
data = data.toString();
|
||||
|
||||
|
@ -133,6 +144,8 @@ var RandomDataGenerator = new Class({
|
|||
n += h * 0x100000000;// 2^32
|
||||
}
|
||||
|
||||
this.n = n;
|
||||
|
||||
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
||||
},
|
||||
|
||||
|
@ -169,9 +182,10 @@ var RandomDataGenerator = new Class({
|
|||
sow: function (seeds)
|
||||
{
|
||||
// Always reset to default seed
|
||||
this.n = 0xefc8249d;
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
this.s1 = this.hash(' ');
|
||||
this.s2 = this.hash(' ');
|
||||
this.c = 1;
|
||||
|
||||
if (!seeds)
|
||||
|
|
Loading…
Add table
Reference in a new issue