Skip to content

Commit

Permalink
Verify number of calls to random for source and destination sim match…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisklus committed Aug 21, 2020
1 parent 60312e5 commit 9800d97
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions js/Random.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ class Random {
// Math.seedrandom is provided by seedrandom.js, see https://github.com/davidbau/seedrandom.
// @private {function:number|null} initialized via setSeed below
this.seedrandom = ( this.seed !== null ) ? new Math.seedrandom( this.seed + '' ) : null;

// @public (read-only) - the number of times `nextDouble` is called
this.numberOfCalls = 0;

Random.allRandomInstances.add( this );
}

/**
* Clears out this instance from all of the Random instances.
* @public
*/
dispose() {
Random.allRandomInstances.delete( this );
}

/**
Expand Down Expand Up @@ -135,6 +148,7 @@ class Random {
* @returns {number} - the random number
*/
nextDouble() {
this.numberOfCalls++;
return this.seed === null ? Math.random() : this.seedrandom(); // eslint-disable-line bad-sim-text
}

Expand Down Expand Up @@ -182,6 +196,8 @@ class Random {
}
}

Random.allRandomInstances = new Set();

dot.register( 'Random', Random );

export default Random;

0 comments on commit 9800d97

Please sign in to comment.