Skip to content

Generate random numbers between two numbers in JavaScript


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;

See also  Mars Exploration - Hackerrank Challenge - Java Solution

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.