_.inRange(n, [start=0], end)

Checks if n is between start and up to but not including, end. If end is not specified it’s set to start with start then set to 0.

Arguments

  1. n (number): The number to check.
  2. [start=0] (number): The start of the range.
  3. end (number): The end of the range.

Returns

(boolean): Returns true if n is in the range, else false.

Example

  1. _.inRange(3, 2, 4);
  2. // => true
  3. _.inRange(4, 8);
  4. // => true
  5. _.inRange(4, 2);
  6. // => false
  7. _.inRange(2, 2);
  8. // => false
  9. _.inRange(1.2, 2);
  10. // => true
  11. _.inRange(5.2, 4);
  12. // => false

_.random([min=0], [max=1], [floating])

Produces a random number between min and max (inclusive). If only one argument is provided a number between 0 and the given number is returned. If floating is true, or either min or max are floats, a floating-point number is returned instead of an integer.

Arguments

  1. [min=0] (number): The minimum possible value.
  2. [max=1] (number): The maximum possible value.
  3. [floating] (boolean): Specify returning a floating-point number.

Returns

(number): Returns the random number.

Example

  1. _.random(0, 5);
  2. // => an integer between 0 and 5
  3. _.random(5);
  4. // => also an integer between 0 and 5
  5. _.random(5, true);
  6. // => a floating-point number between 0 and 5
  7. _.random(1.2, 5.2);
  8. // => a floating-point number between 1.2 and 5.2