Combining Math.random and Math.floor to Generate Random Integers in Javascript


You can generate random integers within a range.

Source Code

function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}
console.log(getRandomInt(10));
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments