Skip to content

Instantly share code, notes, and snippets.

@b-rucel
Last active February 3, 2017 08:18
Show Gist options
  • Save b-rucel/1674717b1f4744a3a328af161bfd0995 to your computer and use it in GitHub Desktop.
Save b-rucel/1674717b1f4744a3a328af161bfd0995 to your computer and use it in GitHub Desktop.
javascript random number with min/max range and incremental number set
function random_number_increment( min, max, inc ) {
let min = min || 0;
let inc = inc || 1;
if ( !max ) {
return new Error( 'Need to define max' );
}
return Math.floor( Math.random() * ( max - min ) / inc ) * inc + min;
}
random_number_increment( 200, 2000, 25 ) // 200, 225, 250 ... 1975, 2000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment