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))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top