This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 4156f7a032e1683c91235890e377703b913265f6
Author: Shad Storhaug <[email protected]>
AuthorDate: Wed Apr 21 17:14:14 2021 +0700

    Lucene.Net.TestFramework: Changed references of RandomGaussian() to use 
RandomizedTesting.Generators. Also changed incorrect references to NextDouble() 
to use NextGaussian() where appropriate.
---
 .../Util/LuceneTestCase.cs                         | 39 +++++-----------------
 src/Lucene.Net.TestFramework/Util/TestUtil.cs      |  2 +-
 .../Codecs/Lucene41/TestBlockPostingsFormat3.cs    |  4 +--
 3 files changed, 12 insertions(+), 33 deletions(-)

diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs 
b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index bd6c9b8..3197a3d 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -2849,7 +2849,7 @@ namespace Lucene.Net.Util
                 else
                 {
                     // advance()
-                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextDouble() * averageGap));
+                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextGaussian() * averageGap));
                     docid = leftDocs.Advance(skip);
                     Assert.AreEqual(docid, rightDocs.Advance(skip), info);
                 }
@@ -2892,7 +2892,7 @@ namespace Lucene.Net.Util
                 else
                 {
                     // advance()
-                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextDouble() * averageGap));
+                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextGaussian() * averageGap));
                     docid = leftDocs.Advance(skip);
                     Assert.AreEqual(docid, rightDocs.Advance(skip), info);
                 }
@@ -3642,15 +3642,12 @@ namespace Lucene.Net.Util
             }
         }
 
-        private double nextNextGaussian; // LUCENENET specific
-        private bool haveNextNextGaussian = false; // LUCENENET specific
-
         /// <summary>
         /// Returns the next pseudorandom, Gaussian ("normally") distributed
         /// <c>double</c> value with mean <c>0.0</c> and standard
         /// deviation <c>1.0</c> from this random number generator's sequence.
         /// <para/>
-        /// The general contract of <c>nextGaussian</c> is that one
+        /// The general contract of <see cref="RandomGaussian()"/> is that one
         /// <see cref="double"/> value, chosen from (approximately) the usual
         /// normal distribution with mean <c>0.0</c> and standard deviation
         /// <c>1.0</c>, is pseudorandomly generated and returned.
@@ -3659,37 +3656,19 @@ namespace Lucene.Net.Util
         /// G. Marsaglia, as described by Donald E. Knuth in <i>The Art of
         /// Computer Programming</i>, Volume 3: <i>Seminumerical 
Algorithms</i>,
         /// section 3.4.1, subsection C, algorithm P. Note that it generates 
two
-        /// independent values at the cost of only one call to 
<c>StrictMath.log</c>
-        /// and one call to <c>StrictMath.sqrt</c>.
+        /// independent values at the cost of only one call to <see 
cref="Math.Log(double)"/>
+        /// and one call to <see cref="Math.Sqrt(double)"/>.
         /// </summary>
         /// <returns>The next pseudorandom, Gaussian ("normally") distributed
         /// <see cref="double"/> value with mean <c>0.0</c> and
         /// standard deviation <c>1.0</c> from this random number
         /// generator's sequence.</returns>
-        // LUCENENET specific - moved this here, since this requires instance 
variables
-        // in order to work. Was originally in 
carrotsearch.randomizedtesting.RandomizedTest.
+        // LUCENENET specific - moved this here so we can reference it more 
readily (similar to how Spatial does it).
+        // However, this is also available as an extension method of the 
System.Random class in RandomizedTesting.Generators.
+        // This method was originally in 
carrotsearch.randomizedtesting.RandomizedTest.
         public double RandomGaussian()
         {
-            // See Knuth, ACP, Section 3.4.1 Algorithm C.
-            if (haveNextNextGaussian)
-            {
-                haveNextNextGaussian = false;
-                return nextNextGaussian;
-            }
-            else
-            {
-                double v1, v2, s;
-                do
-                {
-                    v1 = 2 * Random.NextDouble() - 1; // between -1 and 1
-                    v2 = 2 * Random.NextDouble() - 1; // between -1 and 1
-                    s = v1 * v1 + v2 * v2;
-                } while (s >= 1 || s == 0);
-                double multiplier = Math.Sqrt(-2 * Math.Log(s) / s);
-                nextNextGaussian = v2 * multiplier;
-                haveNextNextGaussian = true;
-                return v1 * multiplier;
-            }
+            return Random.NextGaussian();
         }
     }
 
diff --git a/src/Lucene.Net.TestFramework/Util/TestUtil.cs 
b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
index c39cac9..7d671c2 100644
--- a/src/Lucene.Net.TestFramework/Util/TestUtil.cs
+++ b/src/Lucene.Net.TestFramework/Util/TestUtil.cs
@@ -963,7 +963,7 @@ namespace Lucene.Net.Util
                 int wordLength = -1;
                 while (wordLength < 0)
                 {
-                    wordLength = (int)(random.NextDouble() * 3 + 
avgWordLength);
+                    wordLength = (int)(random.NextGaussian() * 3 + 
avgWordLength);
                 }
                 wordLength = Math.Min(wordLength, maxLength - sb.Length);
                 sb.Append(RandomSubString(random, wordLength, simple));
diff --git a/src/Lucene.Net.Tests/Codecs/Lucene41/TestBlockPostingsFormat3.cs 
b/src/Lucene.Net.Tests/Codecs/Lucene41/TestBlockPostingsFormat3.cs
index 214ab67..e358057 100644
--- a/src/Lucene.Net.Tests/Codecs/Lucene41/TestBlockPostingsFormat3.cs
+++ b/src/Lucene.Net.Tests/Codecs/Lucene41/TestBlockPostingsFormat3.cs
@@ -469,7 +469,7 @@ namespace Lucene.Net.Codecs.Lucene41
                 else
                 {
                     // advance()
-                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextDouble() * averageGap));
+                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextGaussian() * averageGap));
                     docid = leftDocs.Advance(skip);
                     Assert.AreEqual(docid, rightDocs.Advance(skip));
                 }
@@ -509,7 +509,7 @@ namespace Lucene.Net.Codecs.Lucene41
                 else
                 {
                     // advance()
-                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextDouble() * averageGap));
+                    int skip = docid + (int)Math.Ceiling(Math.Abs(skipInterval 
+ Random.NextGaussian() * averageGap));
                     docid = leftDocs.Advance(skip);
                     Assert.AreEqual(docid, rightDocs.Advance(skip));
                 }

Reply via email to