Created
January 21, 2020 13:27
-
-
Save irfanbaigse/155a5c8a786c90227c8bbcc8446d8f59 to your computer and use it in GitHub Desktop.
generate random int between range in javascript or nodejs or js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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