title: Generating the list of random numbers with certain average difference
body: <p>I have to generate a list of random numbers and they have to have a given average difference. For example, a given average difference is 10, so these numbers are good: <code>1 3 5 9 15 51</code>. What I do, is multiply the given average difference by 2 and add 1. Like this:</p>
  
  <pre><code>    while (i &lt;= 50000)
      {
          i += Math.random() * givenAverageDiff * 2 + 1;
          list.add(i);
      }
  </code></pre>
  
  <p>But I never get 5000 or more. In fact, it's always 4,850 or less. Why? Let's say <code>givenAverageDiff</code> is 10. What's my mistake? How can I fix it?</p>
  
  <p>P.S. Implementation in C or PHP is also good for me.</p>