Generating random number in JavaScript

In JavaScript, you can generate a random number using the random() method. This method returns a number between 0 and 1 (including 0). 


<!DOCTYPE html>
<p id="msparagraph"></p>
<button onclick="msrandom()">Generate random number</button>

function msrandom()
var p=document.getElementById('msparagraph');


Random number between two values

function getRandom(min, max)
var res=(Math.random() * (max - min) + min);
<p id="msparagraph1"></p>
<button onclick="getRandom(10, 20)"> Generate Random Numbers</button>
Buy me a coffeeBuy me a coffee

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.

Facebook Twitter Instagram YouTube Pinterest