This tutorial will show you quickly how you can generate random number in Javascript.

The syntax to generate a random number is by using the following function:

Math.random()

Example of returning a random number between 1 and 100:

Math.floor((Math.random()*100)+1);

You can as well create a simple javascript function to accept minimum and maximum number to be generated. Here is the sample function:

function generateRandomNumber (minNumber, maxNumber) { return Math.floor(Math.random() * (maxNumber - minNumber + 1)) + minNumber; }

To use above sample function:

generateRandomNumber(100,1000);