Created
January 5, 2021 15:25
-
-
Save Jagathishrex/b0838a586162dafe855bf3421a13db51 to your computer and use it in GitHub Desktop.
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
// Returns a random number(float) between min (inclusive) and max (exclusive) | |
const getRandomNumber = (min, max) => Math.random() * (max - min) + min; | |
getRandomNumber(2, 10) | |
// Returns a random number(int) between min (inclusive) and max (inclusive) | |
const getRandomNumberInclusive =(min, max)=> { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
getRandomNumberInclusive(2, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment