Created
October 7, 2018 19:55
-
-
Save avisek/b0fa7d16fea08878d2707df583a1d164 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
// Getting a random number between 0 (inclusive) and 1 (exclusive) | |
function getRandom() { | |
return Math.random(); | |
} | |
// Getting a random number between two values | |
function getRandomArbitrary(min, max) { | |
return Math.random() * (max - min) + min; | |
} | |
// Getting a random integer between two values | |
function getRandomInt(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive | |
} | |
// Getting a random integer between two values, inclusive | |
function getRandomIntInclusive(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment