phetsims / dot

A math library with a focus on mutable and immutable linear algebra for 2D and 3D applications.
MIT License
13 stars 6 forks source link

add Random nextDoubleBetween #94

Closed pixelzoom closed 5 years ago

pixelzoom commented 5 years ago

Random has nextIntBetween, but no nextDoubleBetween.

@jonathanolson OK if I add this, of would you prefer a different implementation?

  /**
   * Randomly selects a double in the range [min,max).
   * @param {number} min
   * @param {number} max
   * @returns {number}
   */
  nextDoubleBetween: function ( min, max ) {
    assert && assert( min < max, 'min must be < max' );
    const value = min + this.nextDouble() * ( max - min );
    assert && assert( value >= min && value < max, `value out of range: ${value}` );
    return value;
  }
pixelzoom commented 5 years ago

I went ahead and added nextDoubleBetween to random. @ariel-phet please assign someone to review.

jonathanolson commented 5 years ago

Looks good to me.