Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b62e1e6

Browse files
committed
Fix RandomNumberGeneratorTest.ConcurrentAccess failures
The ConcurrentAccess test is attempting to check statistical variance of the generated random values by verifying that the number of bits that are 0 is approximately the same as the number of bits that are 1s. The test is allowing for a 3% variance, but at that level the test has already failed in CI builds several times. I ran the test locally hundreds of thousands of times, and it's failing 2-3% of all runs, on both Windows and Linux. I changed it to allow for a 4% variance, and it still failed a handful. At a million runs and 5% variance, it still failed a few. At 6% variance, I couldn't get it to fail, so I've changed it to 7% to leave some further buffer. (At some point we should probably do some slightly better test for the random distribution, such as a chi squared test.)
1 parent 98576a8 commit b62e1e6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/System.Security.Cryptography.RandomNumberGenerator/tests/RandomNumberGeneratorTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ private static void AssertNeutralParity(byte[] random)
202202

203203
// Over the long run there should be about as many 1s as 0s.
204204
// This isn't a guarantee, just a statistical observation.
205-
// Allow a 3% tolerance band before considering it to have gotten out of hand.
206-
Assert.True(bitDifference < 0.03);
205+
// Allow a 7% tolerance band before considering it to have gotten out of hand.
206+
const double AllowedTolerance = 0.07;
207+
Assert.True(bitDifference < AllowedTolerance,
208+
"Expected bitDifference < " + AllowedTolerance + ", got " + bitDifference + ".");
207209
}
208210
}
209-
}
211+
}

0 commit comments

Comments
 (0)