2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Generating random numbers in Javascript in a specific range?

I have two variables in Javascript, e.g. x = 4 and y = 8

How to generate a random whole number between two specified variables ?

userimage
function getRandomNumber(minimum, maximum) {
    return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
}

Answer is