JavaScript random

The JavaScript random function returns the Pseudo-random numbers between Zero and One, and the syntax of this is:


JavaScript random Example

This Function returns the floating point Pseudo-random numbers between 0 to 1.

<!DOCTYPE html>
  <h1> JavaScriptMathRANDOM()Function </h1>
  <p id = "P1"></p>
  <p id = "P2"></p>
  <p id = "P3"></p>
  <p id = "P4"></p>
    document.getElementById("P1").innerHTML = Math.random();
    document.getElementById("P2").innerHTML = Math.random();
    document.getElementById("P3").innerHTML = Math.random();
    document.getElementById("P4").innerHTML = Math.random();

The random value generated by this is from the range 0 (included) and less than 1. If you observe the below screenshot, We called the Math function four times, and it returned four different (random) values.

JavaScript RANDOM Example

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.