Skip to content

Instantly share code, notes, and snippets.

@adarrra
Created September 14, 2016 12:10
Show Gist options
  • Save adarrra/0c07b693a86f52094ed1d4fa9b67d88a to your computer and use it in GitHub Desktop.
Save adarrra/0c07b693a86f52094ed1d4fa9b67d88a to your computer and use it in GitHub Desktop.
random number with step
function randomWithStep(min, max, step) {
let prev;
return function () {
let current;
function countFormula() {
current = min + (step * Math.floor(Math.random()*(max-min)/step));
}
do {
countFormula();
}
while (prev === current);
prev = current;
return current;
};
}
let randomNumber = randomWithStep(10, 80, 10);
randomNumber();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment