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);
Written by Bruce Lim
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Random
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#