html random number code example

Example 1: javascript random number between 1 and 10

// Genereates a number between 0 to 1;
Math.random();

// to gerate a randome rounded number between 1 to 10;
var theRandomNumber = Math.floor(Math.random() * 10) + 1;

Example 2: generate random numbers in js

Math.floor((Math.random() * 100) + 1);
//Generate random numbers between 1 and 100
//Math.random generates [0,1)

Example 3: javascript random number between 0 and 10

Math.floor(Math.random() * 10);

Example 4: get random numbers javascript

//Write the following code to get a random number between 0 and n
Math.floor(Math.random() * n);

Example 5: how to generate random number in javascript

var randomNo = Math.floor(Math.rand() * 10000000001);
console.log(randomNo);

//This will generate random number