You can use the examples given in the Math.random
docs page,
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
console.log(getRandomInt(2, number) - 1);
题
I was looking at python script when I have across this:
randomNumber = random.randint(2, number)-1
How can I translate this into javascript?
Thanks?
解决方案
You can use the examples given in the Math.random
docs page,
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
console.log(getRandomInt(2, number) - 1);
其他提示
randomNumber = Math.floor(Math.random() * (1 + number))