Frage

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?

War es hilfreich?

Lösung

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);

Andere Tipps

randomNumber = Math.floor(Math.random() * (1 + number))
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top