Advertisement
aaaaaa123456789

Basic random number generator

Jan 28th, 2014
190
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <script>
  5.       function convert_number (value) {
  6.         return Math.floor((new Number(value)).valueOf());
  7.       }
  8.      
  9.       function generate () {
  10.         var min = document.getElementById("min").value;
  11.         var max = document.getElementById("max").value;
  12.         min = convert_number(min);
  13.         max = convert_number(max);
  14.         if (min >= max)
  15.           document.getElementById("result").innerHTML = "error";
  16.         else {
  17.           var random_number = Math.floor(Math.random() * (max - min + 1)) + min;
  18.           document.getElementById("result").innerHTML = random_number;
  19.         }
  20.       }
  21.     </script>
  22.   </head>
  23.   <body>
  24.     Min: <input type="text" id="min" value="1" /><br />
  25.     Max: <input type="text" id="max" value="10" /><br />
  26.     <button onclick="generate()">Generate!</button><br />
  27.     <p>Generated: <b id="result">nothing</b></p>
  28.   </body>
  29. </html>
Advertisement
RAW Paste Data Copied
Advertisement