Study Guides | javascript | Random Number Generator

Study Guide: Random Number Generator

HTML

  <html>
    <head>
      <title>Random Number Generator</title>
    </head>
    <body>
      <div>
          <h1 id="random_num"></h1>
      </div>
    </body>
  </html>

Javascript

  <script>
      setInterval(function() {
      var number = 1 + Math.floor(Math.random() * 9999);
      $('#random_num').text(number);
      },
      500); // every 0.5 seconds
  </script>

Result

Source: https://class.ronliskey.com/study/computing/random_numbers/