public async Task TestChiSquareDistribution01() { using var rng = new MultiThreadedRng(); var dist = new FastRng.Float.Distributions.ChiSquareK4(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) { fqa.CountThis(await dist.NextNumber()); } var result = fqa.NormalizeAndPlotEvents(TestContext.WriteLine); Assert.That(result[0], Is.EqualTo(0.016417705906679f).Within(0.02f)); Assert.That(result[1], Is.EqualTo(0.032671644513723f).Within(0.02f)); Assert.That(result[2], Is.EqualTo(0.048763041010352f).Within(0.02f)); Assert.That(result[21], Is.EqualTo(0.32518779111264f).Within(0.05f)); Assert.That(result[22], Is.EqualTo(0.338273451612642f).Within(0.05f)); Assert.That(result[23], Is.EqualTo(0.351220492939994f).Within(0.05f)); Assert.That(result[50], Is.EqualTo(0.65209223303425f).Within(0.08f)); Assert.That(result[75], Is.EqualTo(0.857562207152294f).Within(0.099f)); Assert.That(result[85], Is.EqualTo(0.923072405412387f).Within(0.099f)); Assert.That(result[90], Is.EqualTo(0.952623623874265f).Within(0.099f)); Assert.That(result[97], Is.EqualTo(0.990616879396201f).Within(0.099f)); Assert.That(result[98], Is.EqualTo(0.995734077068522f).Within(0.099f)); Assert.That(result[99], Is.EqualTo(1.00077558852585f).Within(0.1f)); }
public async Task TestChiSquareGeneratorWithRange01() { using var rng = new MultiThreadedRng(); var dist = new FastRng.Float.Distributions.ChiSquareK4(rng); var samples = new float[1_000];