Created
March 8, 2013 16:06
-
-
Save osartun/5117521 to your computer and use it in GitHub Desktop.
A shorthand for Math.random() * scale: Instead of multiplying Math.random's result, you can pass your scale as the argument to Math.random Before: Math.random() * 4
Now: Math.random(4)
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
Math.random = (function (_random) { | |
// _random is the reference to the original / native random | |
return function (scale) { | |
(scale && scale === +scale) || (scale = 1); // Make sure scale is set and a number !== 0 | |
return _random() * scale; | |
} | |
})(Math.random); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment