Created
November 13, 2013 04:17
-
-
Save catdad/7443620 to your computer and use it in GitHub Desktop.
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
function generator(low, high, post){ | |
return function(override){ | |
if (!post || typeof post !== "function") post = function(arg){return arg}; | |
return post( Math.random() * (high - low) + low ); | |
} | |
} | |
//example | |
var rand = generator(0,10); // random doubles between 0 and 10 | |
var rand = generator(1,100,Math.round); // random ints between 1 and 100 | |
var rand = generator(0,99,function(num){ return num.toString() }); // random double between 0 and 99 in a string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment