Created
September 14, 2016 12:10
-
-
Save adarrra/0c07b693a86f52094ed1d4fa9b67d88a to your computer and use it in GitHub Desktop.
random number with step
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
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