Skip to content

Commit

Permalink
create dotRandom and use instead of phet.joist.random, phetsims/joist…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jan 22, 2021
1 parent 3052960 commit 571164a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions js/linegame/model/BaseChallengeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import dotRandom from '../../../../dot/js/dotRandom.js';
import Utils from '../../../../dot/js/Utils.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import merge from '../../../../phet-core/js/merge.js';
Expand Down Expand Up @@ -85,13 +86,13 @@ class BaseChallengeFactory {
// x
const minX = ( run >= 0 ) ? graphXRange.min : graphXRange.min - run;
const maxX = ( run >= 0 ) ? graphXRange.max - run : graphXRange.max;
const x = Utils.roundSymmetric( minX + ( phet.joist.random.nextDouble() * ( maxX - minX ) ) );
const x = Utils.roundSymmetric( minX + ( dotRandom.nextDouble() * ( maxX - minX ) ) );
assert && assert( x >= minX && x <= maxX, 'x out of range: ' + x );

// y
const minY = ( rise >= 0 ) ? graphYRange.min : graphYRange.min - rise;
const maxY = ( rise >= 0 ) ? graphYRange.max - rise : graphYRange.max;
const y = Utils.roundSymmetric( minY + ( phet.joist.random.nextDouble() * ( maxY - minY ) ) );
const y = Utils.roundSymmetric( minY + ( dotRandom.nextDouble() * ( maxY - minY ) ) );
assert && assert( y >= minY && y <= maxY, 'y out of range: ' + y );

return new Vector2( x, y );
Expand All @@ -116,13 +117,13 @@ class BaseChallengeFactory {
// x1 coordinates
const minX1 = ( run >= 0 ) ? graphXRange.max - run + 1 : graphXRange.min;
const maxX1 = ( run >= 0 ) ? graphXRange.max : graphXRange.min - run - 1;
const x1 = Utils.roundSymmetric( minX1 + ( phet.joist.random.nextDouble() * ( maxX1 - minX1 ) ) );
const x1 = Utils.roundSymmetric( minX1 + ( dotRandom.nextDouble() * ( maxX1 - minX1 ) ) );
assert && assert( x1 >= minX1 && x1 <= maxX1, 'x1 out of range: ' + x1 );

// y1 coordinates
const minY1 = ( rise >= 0 ) ? graphYRange.max - rise + 1 : graphYRange.min;
const maxY1 = ( rise >= 0 ) ? graphYRange.max : graphYRange.min - rise - 1;
const y1 = Utils.roundSymmetric( minY1 + ( phet.joist.random.nextDouble() * ( maxY1 - minY1 ) ) );
const y1 = Utils.roundSymmetric( minY1 + ( dotRandom.nextDouble() * ( maxY1 - minY1 ) ) );
assert && assert( y1 >= minY1 && y1 <= maxY1, 'y1 out of range: ' + y1 );

// compute (x2,y2) for validation
Expand Down
3 changes: 2 additions & 1 deletion js/linegame/model/BaseGameModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Property from '../../../../axon/js/Property.js';
import dotRandom from '../../../../dot/js/dotRandom.js';
import GameTimer from '../../../../vegas/js/GameTimer.js';
import GLConstants from '../../common/GLConstants.js';
import GLQueryParameters from '../../common/GLQueryParameters.js';
Expand Down Expand Up @@ -256,7 +257,7 @@ class BaseGameModel {
// generate challenges
this.challenges = this.challengeFactories[ level ].createChallenges();
if ( GLQueryParameters.shuffle ) {
this.challenges = phet.joist.random.shuffle( this.challenges );
this.challenges = dotRandom.shuffle( this.challenges );
}

// set the number of challenges
Expand Down
3 changes: 2 additions & 1 deletion js/linegame/model/ValuePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import dotRandom from '../../../../dot/js/dotRandom.js';
import merge from '../../../../phet-core/js/merge.js';
import graphingLines from '../../graphingLines.js';

Expand Down Expand Up @@ -67,7 +68,7 @@ class ValuePool {
*/
static choose( array ) {
assert && assert( array && array.length > 0, 'array is empty' );
const index = phet.joist.random.nextIntBetween( 0, array.length - 1 );
const index = dotRandom.nextIntBetween( 0, array.length - 1 );
assert && assert( index !== -1 );
const item = array[ index ];
array.splice( index, 1 );
Expand Down
7 changes: 4 additions & 3 deletions js/linegame/view/GLRewardNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import Property from '../../../../axon/js/Property.js';
import dotRandom from '../../../../dot/js/dotRandom.js';
import Utils from '../../../../dot/js/Utils.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
import FaceNode from '../../../../scenery-phet/js/FaceNode.js';
Expand Down Expand Up @@ -137,7 +138,7 @@ function getRandomY() {
}

function getRandomNonZeroInteger( min, max ) {
let i = Utils.roundSymmetric( min + ( phet.joist.random.nextDouble() * ( max - min ) ) );
let i = Utils.roundSymmetric( min + ( dotRandom.nextDouble() * ( max - min ) ) );
if ( i === 0 ) { i = 1; }
return i;
}
Expand All @@ -150,7 +151,7 @@ function getRandomNonZeroInteger( min, max ) {
// Creates a random equation with the specified color.
function createEquationNode( color ) {
let node;
if ( phet.joist.random.nextDouble() < 0.5 ) {
if ( dotRandom.nextDouble() < 0.5 ) {
node = SlopeInterceptEquationNode.createDynamicLabel(
new Property( Line.createSlopeIntercept( getRandomY(), getRandomX(), getRandomY(), color ) ), {
fontSize: EQUATION_FONT_SIZE
Expand All @@ -168,7 +169,7 @@ function createEquationNode( color ) {
// Creates a random graph with the specified color.
function createGraphNode( color ) {
let node;
if ( phet.joist.random.nextDouble() < 0.5 ) {
if ( dotRandom.nextDouble() < 0.5 ) {
node = GLIconFactory.createGraphIcon( GRAPH_WIDTH, color, -3, -3, 3, 3 ); // y = +x
}
else {
Expand Down

0 comments on commit 571164a

Please sign in to comment.