Skip to content

Instantly share code, notes, and snippets.

@irfanbaigse
Created January 21, 2020 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irfanbaigse/155a5c8a786c90227c8bbcc8446d8f59 to your computer and use it in GitHub Desktop.
Save irfanbaigse/155a5c8a786c90227c8bbcc8446d8f59 to your computer and use it in GitHub Desktop.
generate random int between range in javascript or nodejs or js
function getRandomInt(lower, upper) {
return Math.floor(Math.random() * (upper - lower + 1)) + lower;
}
console.log(getRandomInt(1,100));
// expected output: a number between 1 and 100
console.log(Math.random());
// expected output: a number between 0 and 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment