When you need a random number between min and max in JavaScript you can use the following code.

var min = 4;
var max = 15;
var randomNumber = Math.max(Math.floor(Math.random() * max) + 1, min);

Last modified: 02/11/2020

Comments

Write a Reply or Comment

Your email address will not be published.