Generate a random number within a range with Javascript | The Dev Tool | Toolel.com

The function below accepts two parameters, the minimum value and the maximum value. Then the function will generate a random number between these two values.

function getRandomNumber(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

console.log(getRandomNumber(1, 10)); // Output: Random number between 1 and 10 (inclusive)

Created by: elvis

Comments

        //

        Created by: elvis</p>
This page is only partially working without JavaScript. It will show content, but the tools and interactivity cannot be shown without JavaScript enabled. Please enable JavaScript for this page. About Us