System.Random.GetSampleForLargeRange C# (CSharp) Method

GetSampleForLargeRange() private method

private GetSampleForLargeRange ( ) : double
return double
      private double GetSampleForLargeRange() {
          // The distribution of double value returned by Sample 
          // is not distributed well enough for a large range.
          // If we use Sample for a range [Int32.MinValue..Int32.MaxValue)
          // We will end up getting even numbers only.

          int result = InternalSample();
          // Note we can't use addition here. The distribution will be bad if we do that.
          bool negative = (InternalSample()%2 == 0) ? true : false;  // decide the sign based on second sample
          if( negative) {
              result = -result;
          }
          double d = result;
          d += (Int32.MaxValue - 1); // get a number in range [0 .. 2 * Int32MaxValue - 1)
          d /= 2*(uint)Int32.MaxValue - 1  ;              
          return d;
      }