title: Javascript - Get a random number within range min and max. Both exclusive
body: <p>I wonder what is the best way to generate a random floating number between min and max. Both min and max are <strong>EXCLUSIVE</strong>.</p>
  
  <p>For example, min = -1, max = 100. Then the random number can be -0.999 or 99.999, but cannot be -1 or 100.</p>
  
  <p>The way I come up is first generate a random number between -1 (inclusive) and 100 (exclusive):</p>
  
  <p><code>Math.random()*(max-min)+min</code></p>
  
  <p>And if the value is equal to -1, get another random number until it's not -1.</p>
  
  <p>The whole thing would be:</p>
  
  <pre><code>var min = -1, max = 100;
  var rand = min;
  while(rand==min)
      rand = Math.random()*(max-min)+min;
  </code></pre>
  
  <p>Is there an even better way to do this so I don't have to possibly run <code>Math.random()</code> several times?</p>