Skip to content

Generate random numbers between two numbers in JavaScript

Advertisements

We can use Math.random() method to generate random numbers between two numbers.

function getRandom(min, max) {
     min = Math.ceil(min);
     max = Math.floor(max);
     return Math.floor(Math.random() * (max - min)) + min;
}
Advertisements

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.