@@ -2849,7 +2849,7 @@ public virtual void AssertDocsSkippingEquals(string info, IndexReader leftReader
2849
2849
else
2850
2850
{
2851
2851
// advance()
2852
- int skip = docid + ( int ) Math . Ceiling ( Math . Abs ( skipInterval + Random . NextDouble ( ) * averageGap ) ) ;
2852
+ int skip = docid + ( int ) Math . Ceiling ( Math . Abs ( skipInterval + Random . NextGaussian ( ) * averageGap ) ) ;
2853
2853
docid = leftDocs . Advance ( skip ) ;
2854
2854
Assert . AreEqual ( docid , rightDocs . Advance ( skip ) , info ) ;
2855
2855
}
@@ -2892,7 +2892,7 @@ public virtual void AssertPositionsSkippingEquals(string info, IndexReader leftR
2892
2892
else
2893
2893
{
2894
2894
// advance()
2895
- int skip = docid + ( int ) Math . Ceiling ( Math . Abs ( skipInterval + Random . NextDouble ( ) * averageGap ) ) ;
2895
+ int skip = docid + ( int ) Math . Ceiling ( Math . Abs ( skipInterval + Random . NextGaussian ( ) * averageGap ) ) ;
2896
2896
docid = leftDocs . Advance ( skip ) ;
2897
2897
Assert . AreEqual ( docid , rightDocs . Advance ( skip ) , info ) ;
2898
2898
}
@@ -3642,15 +3642,12 @@ internal static void LogNativeFSFactoryDebugInfo()
3642
3642
}
3643
3643
}
3644
3644
3645
- private double nextNextGaussian ; // LUCENENET specific
3646
- private bool haveNextNextGaussian = false ; // LUCENENET specific
3647
-
3648
3645
/// <summary>
3649
3646
/// Returns the next pseudorandom, Gaussian ("normally") distributed
3650
3647
/// <c>double</c> value with mean <c>0.0</c> and standard
3651
3648
/// deviation <c>1.0</c> from this random number generator's sequence.
3652
3649
/// <para/>
3653
- /// The general contract of <c>nextGaussian</c > is that one
3650
+ /// The general contract of <see cref="RandomGaussian()"/ > is that one
3654
3651
/// <see cref="double"/> value, chosen from (approximately) the usual
3655
3652
/// normal distribution with mean <c>0.0</c> and standard deviation
3656
3653
/// <c>1.0</c>, is pseudorandomly generated and returned.
@@ -3659,37 +3656,19 @@ internal static void LogNativeFSFactoryDebugInfo()
3659
3656
/// G. Marsaglia, as described by Donald E. Knuth in <i>The Art of
3660
3657
/// Computer Programming</i>, Volume 3: <i>Seminumerical Algorithms</i>,
3661
3658
/// section 3.4.1, subsection C, algorithm P. Note that it generates two
3662
- /// independent values at the cost of only one call to <c>StrictMath.log</c >
3663
- /// and one call to <c>StrictMath.sqrt</c >.
3659
+ /// independent values at the cost of only one call to <see cref="Math.Log(double)"/ >
3660
+ /// and one call to <see cref="Math.Sqrt(double)"/ >.
3664
3661
/// </summary>
3665
3662
/// <returns>The next pseudorandom, Gaussian ("normally") distributed
3666
3663
/// <see cref="double"/> value with mean <c>0.0</c> and
3667
3664
/// standard deviation <c>1.0</c> from this random number
3668
3665
/// generator's sequence.</returns>
3669
- // LUCENENET specific - moved this here, since this requires instance variables
3670
- // in order to work. Was originally in carrotsearch.randomizedtesting.RandomizedTest.
3666
+ // LUCENENET specific - moved this here so we can reference it more readily (similar to how Spatial does it).
3667
+ // However, this is also available as an extension method of the System.Random class in RandomizedTesting.Generators.
3668
+ // This method was originally in carrotsearch.randomizedtesting.RandomizedTest.
3671
3669
public double RandomGaussian ( )
3672
3670
{
3673
- // See Knuth, ACP, Section 3.4.1 Algorithm C.
3674
- if ( haveNextNextGaussian )
3675
- {
3676
- haveNextNextGaussian = false ;
3677
- return nextNextGaussian ;
3678
- }
3679
- else
3680
- {
3681
- double v1 , v2 , s ;
3682
- do
3683
- {
3684
- v1 = 2 * Random . NextDouble ( ) - 1 ; // between -1 and 1
3685
- v2 = 2 * Random . NextDouble ( ) - 1 ; // between -1 and 1
3686
- s = v1 * v1 + v2 * v2 ;
3687
- } while ( s >= 1 || s == 0 ) ;
3688
- double multiplier = Math . Sqrt ( - 2 * Math . Log ( s ) / s ) ;
3689
- nextNextGaussian = v2 * multiplier ;
3690
- haveNextNextGaussian = true ;
3691
- return v1 * multiplier ;
3692
- }
3671
+ return Random . NextGaussian ( ) ;
3693
3672
}
3694
3673
}
3695
3674
0 commit comments