Skip to content

Instantly share code, notes, and snippets.

@macro6461
Created April 1, 2021 13:10
Show Gist options
  • Save macro6461/47641cc6ca57238309966e06b639c81b to your computer and use it in GitHub Desktop.
Save macro6461/47641cc6ca57238309966e06b639c81b to your computer and use it in GitHub Desktop.
This is the gist for How to Obtain Random Numbers Within a Range Using JavaScript.
const randomNumber = (a, b) => {
var min = a > b ? b : a
var max = a > b ? a : b
//Use below if final number doesn't need to be whole number
//return Math.random() * (max - min + 1) + min;
return Math.floor(Math.random() * (max - min + 1) + min);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment