title: RNG gaussian distribution
body: <p>What I'm trying to do isn't exactly a Gaussian distribution, since it has a finite minimum and maximum. The idea is closer to rolling X dice and counting the total.</p>
  <p>I currently have the following function:</p>
  <pre><code>function bellcurve($min=0,$max=100,$entropy=-1) {
      $sum = 0;
      if( $entropy &lt; 0) $entropy = ($max-$min)/15;
      for($i=0; $i&lt;$entropy; $i++) $sum += rand(0,15);
      return floor($sum/(15*$entropy)*($max-$min)+$min);
  }
  </code></pre>
  <p>The idea behind the <code>$entropy</code> variable is to try and roll enough dice to get a more even distribution of fractional results (so that flooring it won't cause problems).</p>
  <p>It doesn't need to be a perfect RNG, it's just for a game feature and nothing like gambling or cryptography.</p>
  <p>However, I ran a test over 65,536 iterations of <code>bellcurve()</code> with no arguments, and the following graph emerged:<br />
  <a href="https://i.stack.imgur.com/8pvTE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8pvTE.png" alt="Graph" /></a><br />
  <sub>(source: <a href="http://adamhaskell.net/img/badentropy.png" rel="nofollow noreferrer">adamhaskell.net</a>)</sub></p>
  <p>As you can see, there are a couple of values that are &quot;offset&quot;, and drastically so. While overall it doesn't really affect that much (at worst it's offset by 2, and ignoring that the probability is still more or less where I want it), I'm just wondering where I went wrong.</p>
  <p>Any additional advice on this function would be appreciated too.</p>
  <p>UPDATE: I fixed the problem above just by using <code>round</code> instead of <code>floor</code>, but I'm still having trouble getting a good function for this. I've tried pretty much every function I can think of, including gaussian, exponential, logistic, and so on, but to no avail. The only method that has worked so far is this approximation of rolling dice, which is almost certainly not what I need...</p>