Created
April 1, 2021 13:10
-
-
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.
This file contains hidden or 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
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