JavaScript random number between two numbers

How generate a random number in a specified range or two numbers (e.g. from 1 to 6: 1, 2, 3, 4, 5, or 6) in JavaScript?

You can get a random integer between 1 (and only 1) and 6, you would calculate:


  • 1 is the start number
  • 6 is the number of possible results (1 + start (6) – end (1))


JavaScript random number between two numbers

Do comment if you have any doubts in this tutorial. Suggestions is always important to us, so do comment.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version

Leave a Reply

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