Last active
August 29, 2015 14:19
-
-
Save gdibble/ed159bdf1a31b90180ec to your computer and use it in GitHub Desktop.
random number generator - lower/upper range, as integer or not
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
/* | |
* return random number within lower/upper range | |
* output a whole number by passing returnInteger=1 | |
* Examples: $R(0, 10); >>> 3.141592653589793 | |
* $R(0, 10, 1); >>> 7 | |
*/ | |
function $R(lowerLimit, upperLimit, returnInteger) { | |
var step1 = Math.random() * (upperLimit - lowerLimit); | |
if (returnInteger && (returnInteger === 1)) { | |
return lowerLimit + parseInt(step1, 10); | |
} else { | |
return lowerLimit + step1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment