Posted on Leave a comment

Get random numbers between 2 values in JavaScript

This function selects random numbers between two numbers you specify.  It is very useful in any situation that needs a random number.  Below is an example from a real case.

function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
document.getElementById('delay').value = getRandomInt(8, 15);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.