Skip to content

Instantly share code, notes, and snippets.

@adarrra
Created September 14, 2016 12:10

Revisions

  1. adarrra created this gist Sep 14, 2016.
    17 changes: 17 additions & 0 deletions random_with_step.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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();