Answers for "w3schools get random int"

1

random int javascript

//Returns random Int between 0 and 2 (included)
Math.floor(Math.random()*3)
Posted by: Guest on July-04-2020
1

random int javascript

/** Generates integers between low (inclusive) and high (exclusive) */
function generateRandomInteger(low, high) {
  const lowCeil = Math.ceil(low);
  const highFloor = Math.floor(high);
  const randomFloat = lowCeil + Math.random() * (highFloor - lowCeil);

  return Math.floor(randomFloat);
}
Posted by: Guest on January-03-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language