Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Created January 5, 2021 15:25
Show Gist options
  • Save Jagathishrex/b0838a586162dafe855bf3421a13db51 to your computer and use it in GitHub Desktop.
Save Jagathishrex/b0838a586162dafe855bf3421a13db51 to your computer and use it in GitHub Desktop.
// 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