Last Updated: February 25, 2016
·
2.789K
· b-rucel

JS random number range & increment

// need to get a random integer between range and in increments

function randomRangeWithIncrements(min, max, inc) {
    min = min || 0;
    inc = inc || 1;
    if(!max) { return new Error('need to define a max');}

    return Math.floor(Math.random() * (max - min) / inc) * inc + min;
}

randomRangeWithIncrements(200, 1000, 25);