title: Math.NET CryptoRandomSource Next is Biased
body: <p>I am developing a gaming platform that is subject to heavy regulatory scrutiny. I chose Math.NET because it seemed like a good fit. However I have just received this comment back from our auditors.</p>
  
  <p>Comments please if this is accurate and how it can be resolved?</p>
  
  <hr>
  
  <p>In RandomSource(), Next(int, int) is defined as follows:</p>
  
  <pre><code>    public override sealed int Next(int minValue, int maxValue)
      {
          if (minValue &gt; maxValue)
          {
              throw new ArgumentException(Resources.ArgumentMinValueGreaterThanMaxValue);
          }
  
          if (_threadSafe)
          {
              lock (_lock)
              {
                  return (int)(DoSample()*(maxValue - minValue)) + minValue;
              }
          }
  
          return (int)(DoSample()*(maxValue - minValue)) + minValue;
      }
  </code></pre>
  
  <p>This creates a bias in the same way as before.  Using an un-scaled value from the RNG and multiplying it by the range without previously eliminating the bias (unless the range is a power of 2, there will be a bias ).  </p>