Last active
January 30, 2018 22:57
-
-
Save sbrl/65b4f778d91ea81eeee5 to your computer and use it in GitHub Desktop.
A simple 3 formed bounded random number generator. #function #microlibrary #random
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
/** | |
* Bounded random number generator. Has 3 forms: | |
* | |
** Form 1 ** | |
* @param {number} a The minimum value. | |
* @param {number} b The maximum value. | |
* @param {boolean} c Whether the resulting number should be a float. [optional] | |
* @return {number} A random number. | |
* | |
** Form 2 ** | |
* @param {number} a The maximum value. | |
* @param {boolean} b Whether the resulting number should be a float. [optional] | |
* @return {number} A random number. | |
* | |
** Form 3 ** | |
* @return {number} A random number. | |
*/ | |
function random(a,b,c,d) | |
{d=Math.random();if(typeof a!="number")return d;a=typeof b=="number"?d*(a-b)+b:d*a;a=(typeof b!="number"?b:c)?a:Math.floor(a);return a;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment