Answers for "function randomrange that accepts a positive number and returns a random number between zero and the passed in argument in javascript"

4

javascript get random integer in given range

const randomInteger = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
Posted by: Guest on July-03-2020
0

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 });
Posted by: Guest on August-14-2021

Code answers related to "function randomrange that accepts a positive number and returns a random number between zero and the passed in argument in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language