Skip to content

Instantly share code, notes, and snippets.

@ischenkodv
Last active October 12, 2015 02:38
Show Gist options
  • Save ischenkodv/3958676 to your computer and use it in GitHub Desktop.
Save ischenkodv/3958676 to your computer and use it in GitHub Desktop.
Generate random number using bitwise operator to round values.
/**
* 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