title: Generate and sort Javascript Random Numbers
body: <p>I started to print 1000 random numbers between 1 to 100  and then  sort  all 1000 numbers.</p>
  
  <p>Here something  wrong happen .</p>
  
  <p>How use Math.random()  for it ?</p>
  
  <pre><code>        &lt;script type="text/javascript" language="Javascript"&gt;
  function pick(n, min, max) {
      var values = [],
          i = max;
      while (i &gt;= min)
          values.push(i--);
      var results = [];
      var maxIndex = max;
      for (i = 1; i &lt;= n; i++) {
          maxIndex--;
          var index = Math.floor(maxIndex * Math.random());
          results.push(values[index]);
          values[index] = values[maxIndex];
      }
      return results;
  }
  
  function go() {
      var running = true;
      do {
          if (!confirm(pick(1000, 1, 100).sort(function(a, b) {
                  return a - b;
              }))) {
              running = false;
          }
      } while (running)
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
           &lt;h1&gt;100  random number between 1 and 100&lt;/h1&gt;
           &lt;p&gt;&lt;button onclick="go()"&gt;Click me&lt;/button&gt; to start generating numbers.&lt;/p&gt;
            &lt;p&gt;When the numbers appear, click OK to generate another set, or Cancel to stop.&lt;/p&gt;
      &lt;/body&gt;
  </code></pre>