Last active
October 12, 2015 02:38
-
-
Save ischenkodv/3958676 to your computer and use it in GitHub Desktop.
Generate random number using bitwise operator to round values.
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
/** | |
* Generate random integer from 0 to limit. | |
*/ | |
function rnd(limit) { | |
return (Math.random()*limit)|0; | |
} | |
/** | |
* Generate random float value in range. | |
*/ | |
function randomFromRange(from, to) { | |
return parseFloat((Math.random() * (from - to) + to).toFixed(5)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment