title: JavaScript: Generating a Random Number According to User Input
body: <p>I wish to build a very simple web page which generates a random number (integer) corresponding to three parameters provided by the user:</p>
  
  <ol>
  <li>A bottom limit number (the output can't be smaller than this number).</li>
  <li>An upper limit number (the output can't be bigger than this number). </li>
  <li>A value between 1 and 9 that defines the number of digits composing the number (length). For example, if the number was set to be anywhere between 1 and 999, this parameter will define whether the resulting number will be somewhere between 1 and 9, 10 and 99, and 100 and 999.</li>
  </ol>
  
  <p>So far, this is what I have:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;!--
  https://docs.google.com/document/d/15tsEtcmWrukVp8NBBxQnBpW-YoegjD_fpyhAgH_7ijA/edit
  --&gt;
  
  &lt;form name="settings"&gt;
  
  How many numbers should be generated? &lt;input type="number" min="1" max="6" name="digits"/&gt;
  &lt;br/&gt;
  Smallest number in the range &lt;input type="number" min="1" max="999998" name="lownum"/&gt;
  &lt;br/&gt;
  Biggest number in the range &lt;input type="number" min="2" max="999999" name="highnum"/&gt;
  &lt;input type="submit" onclick="validate()"&gt;
  
  &lt;/form&gt;
  
  &lt;script&gt;
  
  function validate(){
  if(parseInt(document.settings.lownum.value)&gt;parseInt(document.settings.highnum.value))
      {
          alert("!");
      }
      else
          {
              document.write(Generator());
          }
  }
  
  function generator() {
      var min = parseInt(document.settings.lownum.value);
      var max = parseInt(document.settings.highnum.value);
      return Math.floor(Math.random() * (max - min +1)) + min
  }
  
  &lt;/script&gt;
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I think I got the lower/upper limit figured out, but I can't say the same regarding the number of digits.</p>
  
  <p>Thanks!</p>