Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Random number given a range js

const randomNumber = ({ min, max } = { min: 0, max: 1 }) => {
  if (min >= max) {
    throw Error(
      `minimum value (${min}) is larger than or equal to maximum value (${max})`
    );
  }

  return Math.floor(Math.random() * Math.floor(max - min + 1) + min);
};

// Usage: random number between 10 and 100.
const n = randomNumber({ min: 10, max: 100 });
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #Random #number #range #js
ADD COMMENT
Topic
Name
1+1 =