Avatar ·

How to generate a random number in a given range in JavaScript?

Hello everyone! I just started learning JavaScript and came across a task that stumped me. I need to write a function that returns a random integer between two values, for example, from 5 to 15 (inclusive). I know about Math.random(), but it returns numbers from 0 to 1. I tried multiplying the result by something, but I get fractional numbers or it goes out of range. Here's what I tried:
function getRandomNumber(min, max) {
    return Math.random() * max; 
}
// Returns a number from 0 to max, but not from min
Then I thought to add min:
function getRandomNumber(min, max) {
    return Math.random() * max + min;
}
// Now numbers are from min to min+max, not from min to max
In short, nothing works as I need.