Added decision support
This commit is contained in:
parent
1df9398746
commit
34fad9dddd
@ -65,5 +65,11 @@ namespace FastRng.Double.Distributions
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<double> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0, 1.0, cancel);
|
public async ValueTask<double> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0, 1.0, cancel);
|
||||||
|
|
||||||
|
public async ValueTask<bool> HasDecisionBeenMade(double above, double below = 1, CancellationToken cancel = default)
|
||||||
|
{
|
||||||
|
var number = await this.NextNumber(cancel);
|
||||||
|
return number > above && number < below;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,5 +14,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public ValueTask<double> NextNumber(double rangeStart, double rangeEnd, CancellationToken cancel = default);
|
public ValueTask<double> NextNumber(double rangeStart, double rangeEnd, CancellationToken cancel = default);
|
||||||
|
|
||||||
public ValueTask<double> NextNumber(CancellationToken cancel = default);
|
public ValueTask<double> NextNumber(CancellationToken cancel = default);
|
||||||
|
|
||||||
|
public ValueTask<bool> HasDecisionBeenMade(double above, double below = 1.0, CancellationToken cancel = default);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -61,5 +61,11 @@ namespace FastRng.Double.Distributions
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<double> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0, 1.0, cancel);
|
public async ValueTask<double> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0, 1.0, cancel);
|
||||||
|
|
||||||
|
public async ValueTask<bool> HasDecisionBeenMade(double above, double below = 1, CancellationToken cancel = default)
|
||||||
|
{
|
||||||
|
var number = await this.NextNumber(cancel);
|
||||||
|
return number > above && number < below;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -65,5 +65,11 @@ namespace FastRng.Float.Distributions
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<float> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0f, 1.0f, cancel);
|
public async ValueTask<float> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0f, 1.0f, cancel);
|
||||||
|
|
||||||
|
public async ValueTask<bool> HasDecisionBeenMade(float above, float below = 1, CancellationToken cancel = default)
|
||||||
|
{
|
||||||
|
var number = await this.NextNumber(cancel);
|
||||||
|
return number > above && number < below;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,5 +14,7 @@ namespace FastRng.Float.Distributions
|
|||||||
public ValueTask<float> NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default);
|
public ValueTask<float> NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default);
|
||||||
|
|
||||||
public ValueTask<float> NextNumber(CancellationToken cancel = default);
|
public ValueTask<float> NextNumber(CancellationToken cancel = default);
|
||||||
|
|
||||||
|
public ValueTask<bool> HasDecisionBeenMade(float above, float below = 1.0f, CancellationToken cancel = default);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -61,5 +61,11 @@ namespace FastRng.Float.Distributions
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<float> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0f, 1.0f, cancel);
|
public async ValueTask<float> NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0f, 1.0f, cancel);
|
||||||
|
|
||||||
|
public async ValueTask<bool> HasDecisionBeenMade(float above, float below = 1, CancellationToken cancel = default)
|
||||||
|
{
|
||||||
|
var number = await this.NextNumber(cancel);
|
||||||
|
return number > above && number < below;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
62
FastRngTests/Double/DecisionTester.cs
Normal file
62
FastRngTests/Double/DecisionTester.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FastRng.Double;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Uniform = FastRng.Double.Distributions.Uniform;
|
||||||
|
|
||||||
|
namespace FastRngTests.Double
|
||||||
|
{
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public class DecisionTester
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.COVER)]
|
||||||
|
[Category(TestCategories.NORMAL)]
|
||||||
|
public async Task DecisionUniform01()
|
||||||
|
{
|
||||||
|
using var rng = new MultiThreadedRng();
|
||||||
|
var dist = new Uniform(rng);
|
||||||
|
|
||||||
|
var neededCoinTossesA = 0;
|
||||||
|
var neededCoinTossesB = 0;
|
||||||
|
var neededCoinTossesC = 0;
|
||||||
|
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.0f, 0.1f)) neededCoinTossesA++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.5f, 0.6f)) neededCoinTossesB++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.8f, 0.9f)) neededCoinTossesC++;
|
||||||
|
|
||||||
|
var values = new[] {neededCoinTossesA, neededCoinTossesB, neededCoinTossesC};
|
||||||
|
var max = values.Max();
|
||||||
|
var min = values.Min();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Coin tosses: a={neededCoinTossesA}, b={neededCoinTossesB}, c={neededCoinTossesC}");
|
||||||
|
Assert.That(max - min, Is.LessThanOrEqualTo(250));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.COVER)]
|
||||||
|
[Category(TestCategories.NORMAL)]
|
||||||
|
public async Task DecisionWeibull01()
|
||||||
|
{
|
||||||
|
using var rng = new MultiThreadedRng();
|
||||||
|
var dist = new FastRng.Double.Distributions.WeibullK05La1(rng);
|
||||||
|
|
||||||
|
var neededCoinTossesA = 0;
|
||||||
|
var neededCoinTossesB = 0;
|
||||||
|
var neededCoinTossesC = 0;
|
||||||
|
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.0f, 0.1f)) neededCoinTossesA++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.5f, 0.6f)) neededCoinTossesB++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.8f, 0.9f)) neededCoinTossesC++;
|
||||||
|
|
||||||
|
var values = new[] {neededCoinTossesA, neededCoinTossesB, neededCoinTossesC};
|
||||||
|
var max = values.Max();
|
||||||
|
var min = values.Min();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Coin tosses: a={neededCoinTossesA}, b={neededCoinTossesB}, c={neededCoinTossesC}");
|
||||||
|
Assert.That(max - min, Is.LessThanOrEqualTo(2_800));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
FastRngTests/Float/DecisionTester.cs
Normal file
64
FastRngTests/Float/DecisionTester.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FastRng.Float;
|
||||||
|
using FastRng.Float.Distributions;
|
||||||
|
using FastRngTests.Float.Distributions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Uniform = FastRng.Float.Distributions.Uniform;
|
||||||
|
|
||||||
|
namespace FastRngTests.Float
|
||||||
|
{
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public class DecisionTester
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.COVER)]
|
||||||
|
[Category(TestCategories.NORMAL)]
|
||||||
|
public async Task DecisionUniform01()
|
||||||
|
{
|
||||||
|
using var rng = new MultiThreadedRng();
|
||||||
|
var dist = new Uniform(rng);
|
||||||
|
|
||||||
|
var neededCoinTossesA = 0;
|
||||||
|
var neededCoinTossesB = 0;
|
||||||
|
var neededCoinTossesC = 0;
|
||||||
|
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.0f, 0.1f)) neededCoinTossesA++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.5f, 0.6f)) neededCoinTossesB++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.8f, 0.9f)) neededCoinTossesC++;
|
||||||
|
|
||||||
|
var values = new[] {neededCoinTossesA, neededCoinTossesB, neededCoinTossesC};
|
||||||
|
var max = values.Max();
|
||||||
|
var min = values.Min();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Coin tosses: a={neededCoinTossesA}, b={neededCoinTossesB}, c={neededCoinTossesC}");
|
||||||
|
Assert.That(max - min, Is.LessThanOrEqualTo(250));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.COVER)]
|
||||||
|
[Category(TestCategories.NORMAL)]
|
||||||
|
public async Task DecisionWeibull01()
|
||||||
|
{
|
||||||
|
using var rng = new MultiThreadedRng();
|
||||||
|
var dist = new FastRng.Float.Distributions.WeibullK05La1(rng);
|
||||||
|
|
||||||
|
var neededCoinTossesA = 0;
|
||||||
|
var neededCoinTossesB = 0;
|
||||||
|
var neededCoinTossesC = 0;
|
||||||
|
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.0f, 0.1f)) neededCoinTossesA++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.5f, 0.6f)) neededCoinTossesB++;
|
||||||
|
for(var n = 0; n < 100; n++) while (!await dist.HasDecisionBeenMade(0.8f, 0.9f)) neededCoinTossesC++;
|
||||||
|
|
||||||
|
var values = new[] {neededCoinTossesA, neededCoinTossesB, neededCoinTossesC};
|
||||||
|
var max = values.Max();
|
||||||
|
var min = values.Min();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Coin tosses: a={neededCoinTossesA}, b={neededCoinTossesB}, c={neededCoinTossesC}");
|
||||||
|
Assert.That(max - min, Is.LessThanOrEqualTo(2_800));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user