For example:
var min = -10;
var max = 10;
console.log(Math.floor(Math.random() * (max - min + 1) + min));
.as-console-wrapper { max-height: 100% !important; top: 0; }
See this jsrandom.php for some comparison of Math.floor
, Math.ceil
and Math.round
.