Skip to content

Instantly share code, notes, and snippets.

@kaleem-elahi
Created June 17, 2021 07:33
Show Gist options
  • Save kaleem-elahi/505f88be112f740f6e5654f91b41b594 to your computer and use it in GitHub Desktop.
Save kaleem-elahi/505f88be112f740f6e5654f91b41b594 to your computer and use it in GitHub Desktop.
how to get a Random number in a Range of Values
const getRandomIntInRange = (min, max) => Math.floor(Math.random() * (max-min +1)) + min;
// 3 examples added to show how to use it:
/*
getRandomIntInRange(1, 5);
Output: 1
getRandomIntInRange(1, 5);
Output: 4
getRandomIntInRange(1, 5);
Output: 1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment