JavaScript RANDOM

The JavaScript RANDOM function returns the Pseudo random numbers between Zero and One. The syntax of the RANDOM Function is:


JavaScript RANDOM Function Example

The RANDOM Function returns the Pseudo random numbers between 0 to 1.

<!DOCTYPE html>
    <title>JavaScript Math.RANDOM Function</title>
  <h1> JavaScript Math.RANDOM() 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 value generated by the RANDOM function is from 0 (included) and less than 1. If you observe the below screenshot, We called the RANDOM Math function for four times, and it was returning four different (random) values.

JavaScript RANDOM Function