Is there a way to generate a random number in a specified range (e.g. from 1 to 6: 1, 2, 3, 4, 5, or 6) in JavaScript?
This works for me and produces values like Python's random.randint standard library function:
function randint(min, max) { return Math.round((Math.random() * Math.abs(max - min)) + min); } console.log("Random integer: " + randint(-5, 5));