How to get a pseudo-random number between 0 and 1 in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get a pseudo-random number between 0 and 1, use the Math.random() method in JavaScript.

Example

You can try to run the following code to get a pseudo-random number between 0 and 1 −

<html>
   <head>
      <title>JavaScript Math random() Method</title>
   </head>
   <body>
      <script>
         var value = Math.random( );
         document.write("First Value : " + value );

         value = Math.random( );
         document.write("<br />Second Value : " + value );
      </script>
   </body>
</html>
raja
Published on 16-Feb-2018 07:15:54
Advertisements