Added float implementations
This commit is contained in:
parent
706f2552bc
commit
1651fbaa2b
13
FastRng/Float/Distributions/BetaA2B2.cs
Normal file
13
FastRng/Float/Distributions/BetaA2B2.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace FastRng.Float.Distributions
|
||||||
|
{
|
||||||
|
public sealed class BetaA2B2 : Distribution
|
||||||
|
{
|
||||||
|
private const float ALPHA = 2f;
|
||||||
|
private const float BETA = 2f;
|
||||||
|
private const float CONSTANT = 4f;
|
||||||
|
|
||||||
|
protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||||
|
}
|
||||||
|
}
|
13
FastRng/Float/Distributions/BetaA2B5.cs
Normal file
13
FastRng/Float/Distributions/BetaA2B5.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace FastRng.Float.Distributions
|
||||||
|
{
|
||||||
|
public sealed class BetaA2B5 : Distribution
|
||||||
|
{
|
||||||
|
private const float ALPHA = 2f;
|
||||||
|
private const float BETA = 5f;
|
||||||
|
private const float CONSTANT = 12.2f;
|
||||||
|
|
||||||
|
protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||||
|
}
|
||||||
|
}
|
13
FastRng/Float/Distributions/BetaA5B2.cs
Normal file
13
FastRng/Float/Distributions/BetaA5B2.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace FastRng.Float.Distributions
|
||||||
|
{
|
||||||
|
public sealed class BetaA5B2 : Distribution
|
||||||
|
{
|
||||||
|
private const float ALPHA = 5f;
|
||||||
|
private const float BETA = 2f;
|
||||||
|
private const float CONSTANT = 12.2f;
|
||||||
|
|
||||||
|
protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||||
|
}
|
||||||
|
}
|
34
FastRng/Float/Distributions/Distribution.cs
Normal file
34
FastRng/Float/Distributions/Distribution.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FastRng.Float.Distributions
|
||||||
|
{
|
||||||
|
public abstract class Distribution : IDistribution
|
||||||
|
{
|
||||||
|
private ShapeFitter fitter;
|
||||||
|
private IRandom random;
|
||||||
|
|
||||||
|
public IRandom Random
|
||||||
|
{
|
||||||
|
get => this.random;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if(this.random != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.random = value;
|
||||||
|
this.fitter = new ShapeFitter(this.ShapeFunction, this.random, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract float ShapeFunction(float x);
|
||||||
|
|
||||||
|
public async ValueTask<float> GetDistributedValue(CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (this.Random == null)
|
||||||
|
return float.NaN;
|
||||||
|
|
||||||
|
return await this.fitter.NextNumber(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user