0 votes
in JavaScript by
Can you write a random integers function to print integers with in a range in Javascript?

1 Answer

0 votes
by

Yes, you can create a proper random function to return a random number between min and max (both included)

function randomInteger(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
randomInteger(1, 100); // returns a random integer from 1 to 100
randomInteger(1, 1000); // returns a random integer from 1 to 1000
...