Get Random Whole Numbers within a Range – JS

Here is a simple Javascript code which gives you a random whole number within the given range of numbers:

var randNum = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;

where, maxNum is the upper limit and minNum is the lower limit of the range, and they are inclusive.

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.

%d bloggers like this: