Random Number Generator

Published on: February 18, 2017

Hey there! Welcome to the 35th Easy JavaScript tutorial, part of EasyProgramming.net. Let's do something we've done in C++. Let's create a random number generator, one that you can put on your website. 

This tutorial shows you how to create a random number from 0 to a number as well as between one number and another. We utilize the Math.random() method available to us in the Math object of JavaScript. Give it a try with the following formula:

    Math.floor(Math.random() * (max - min + 1)) + min

To fork the fiddle and follow along: https://jsfiddle.net/easyjs/hnvm0fg1/

Also check out my C++ random number generator which has helped thousands of people: https://youtu.be/Wh-dFCpVQyY

Get the code here: C++ Random Number Generator Tutorial

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!