Skip to content

Instantly share code, notes, and snippets.

@osartun
Created March 8, 2013 16:06
Show Gist options
  • Save osartun/5117521 to your computer and use it in GitHub Desktop.
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)
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