public void TestNextGaussian() { Assert.Throws <ArgumentNullException>(() => Rand.NextGaussian(null)); var rand = this.GetRandom(); var gaussians = Enumerable.Range(0, 10000).Select(_ => rand.NextGaussian()).ToArray(); var average = gaussians.Average(); var stdev = RandTest.StandardDeviation(gaussians); Assert.True(Math.Abs(average) < 0.05, "was " + average); Assert.True(Math.Abs(stdev - 1) < 0.05, "was " + average); }
public void TestShuffled() { Assert.Throws <ArgumentNullException>(() => Rand.Shuffled <int>(null, this.GetRandom())); Enumerable.Range(0, 100) .Shuffled(this.GetRandom()) .OrderBy(i => i) .SequenceShouldEqual(Enumerable.Range(0, 100)); var shuffled = Enumerable.Range(0, 5000) .Shuffled(this.GetRandom()) .ToArray(); var correlation = RandTest.Correlation(shuffled.Select(Convert.ToDouble).ToArray(), Enumerable.Range(0, shuffled.Length).Select(Convert.ToDouble).ToArray()); Assert.True(Math.Abs(correlation) < .05, correlation.ToString()); }
public void TestShuffle() { Assert.Throws <ArgumentNullException>(() => Rand.Shuffle <int>(null, this.GetRandom())); var numbers = Enumerable.Range(0, 100).ToList(); numbers.Shuffle(this.GetRandom()); numbers.Sort(); numbers.SequenceShouldEqual(Enumerable.Range(0, 100)); var list = Enumerable.Range(0, 2000).ToList(); list.Shuffle(this.GetRandom()); var correlation = RandTest.Correlation(list.Select(Convert.ToDouble).ToArray(), Enumerable.Range(0, list.Count).Select(Convert.ToDouble).ToArray()); Assert.True(Math.Abs(correlation) < .05, correlation.ToString()); }