JavaScript Math.random() Method
You are Here:
JavaScript Math.random() Method
The Math.random()
method returns a floating-point random number between 0 (inclusive) and 1 (exclusive).
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var result = Math.random();
document.write(result);
</script>
</body>
</html>
Syntax
Math.random()
Return Value
Value | Explanation |
---|---|
Number | A floating-point random number between 0 (inclusive) and 1 (exclusive). |
Random Number Between 0 and 100
Note: The following example is the random number between 0 (inclusive) and 100 (exclusive).
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
// Click 'Run' button multiple times.
var result = Math.floor(Math.random() * 100);
document.write(result);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.