diff --git a/FastRng/Distributions/BetaA2B2.cs b/FastRng/Distributions/BetaA2B2.cs index b2864aa..81e9564 100644 --- a/FastRng/Distributions/BetaA2B2.cs +++ b/FastRng/Distributions/BetaA2B2.cs @@ -1,16 +1,16 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class BetaA2B2 : Distribution +public sealed class BetaA2B2 : Distribution where TNum : IFloatingPointIeee754 { - private const float ALPHA = 2f; - private const float BETA = 2f; - private const float CONSTANT = 4f; + private static readonly TNum ALPHA = TNum.One + TNum.One; + private static readonly TNum BETA = TNum.One + TNum.One; + private static readonly TNum CONSTANT = TNum.CreateChecked(4); - public BetaA2B2(IRandom rng) : base(rng) + public BetaA2B2(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * TNum.Pow(x, ALPHA - TNum.One) * TNum.Pow(TNum.One - x, BETA - TNum.One); } \ No newline at end of file diff --git a/FastRng/Distributions/BetaA2B5.cs b/FastRng/Distributions/BetaA2B5.cs index acaba4c..77b7315 100644 --- a/FastRng/Distributions/BetaA2B5.cs +++ b/FastRng/Distributions/BetaA2B5.cs @@ -1,16 +1,16 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class BetaA2B5 : Distribution +public sealed class BetaA2B5 : Distribution where TNum : IFloatingPointIeee754 { - private const float ALPHA = 2f; - private const float BETA = 5f; - private const float CONSTANT = 12.2f; + private static readonly TNum ALPHA = TNum.One + TNum.One; + private static readonly TNum BETA = TNum.CreateChecked(5); + private static readonly TNum CONSTANT = TNum.CreateChecked(12.2f); - public BetaA2B5(IRandom rng) : base(rng) + public BetaA2B5(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * TNum.Pow(x, ALPHA - TNum.One) * TNum.Pow(TNum.One - x, BETA - TNum.One); } \ No newline at end of file diff --git a/FastRng/Distributions/BetaA5B2.cs b/FastRng/Distributions/BetaA5B2.cs index b2dc15a..f9af4f1 100644 --- a/FastRng/Distributions/BetaA5B2.cs +++ b/FastRng/Distributions/BetaA5B2.cs @@ -1,16 +1,16 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class BetaA5B2 : Distribution +public sealed class BetaA5B2 : Distribution where TNum : IFloatingPointIeee754 { - private const float ALPHA = 5f; - private const float BETA = 2f; - private const float CONSTANT = 12.2f; + private static readonly TNum ALPHA = TNum.CreateChecked(5f); + private static readonly TNum BETA = TNum.One + TNum.One; + private static readonly TNum CONSTANT = TNum.CreateChecked(12.2f); - public BetaA5B2(IRandom rng) : base(rng) + public BetaA5B2(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * TNum.Pow(x, ALPHA - TNum.One) * TNum.Pow(TNum.One - x, BETA - TNum.One); } \ No newline at end of file diff --git a/FastRng/Distributions/CauchyLorentzX0.cs b/FastRng/Distributions/CauchyLorentzX0.cs index 2f4d2db..52fc302 100644 --- a/FastRng/Distributions/CauchyLorentzX0.cs +++ b/FastRng/Distributions/CauchyLorentzX0.cs @@ -1,16 +1,17 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class CauchyLorentzX0 : Distribution +public sealed class CauchyLorentzX0 : Distribution where TNum : IFloatingPointIeee754 { - private const float CONSTANT = 0.31f; - private const float SCALE = 0.1f; - private const float MEDIAN = 0.0f; + private static readonly TNum CONSTANT = TNum.CreateChecked(0.31f); + private static readonly TNum SCALE = TNum.CreateChecked(0.1f); + private static readonly TNum MEDIAN = TNum.Zero; + private static readonly TNum TWO = TNum.CreateChecked(2f); - public CauchyLorentzX0(IRandom rng) : base(rng) + public CauchyLorentzX0(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * (1.0f / (MathF.PI * SCALE)) * ((SCALE * SCALE) / (MathF.Pow(x - MEDIAN, 2f) + (SCALE * SCALE))); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * ( TNum.One / (TNum.Pi * SCALE)) * ((SCALE * SCALE) / (TNum.Pow(x - MEDIAN, TWO) + (SCALE * SCALE))); } \ No newline at end of file diff --git a/FastRng/Distributions/CauchyLorentzX1.cs b/FastRng/Distributions/CauchyLorentzX1.cs index 121b24d..bda6296 100644 --- a/FastRng/Distributions/CauchyLorentzX1.cs +++ b/FastRng/Distributions/CauchyLorentzX1.cs @@ -1,16 +1,17 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class CauchyLorentzX1 : Distribution +public sealed class CauchyLorentzX1 : Distribution where TNum : IFloatingPointIeee754 { - private const float CONSTANT = 0.31f; - private const float SCALE = 0.1f; - private const float MEDIAN = 1.0f; + private static readonly TNum CONSTANT = TNum.CreateChecked(0.31f); + private static readonly TNum SCALE = TNum.CreateChecked(0.1f); + private static readonly TNum MEDIAN = TNum.One; + private static readonly TNum TWO = TNum.CreateChecked(2f); - public CauchyLorentzX1(IRandom rng) : base(rng) + public CauchyLorentzX1(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * (1.0f / (MathF.PI * SCALE)) * ((SCALE * SCALE) / (MathF.Pow(x - MEDIAN, 2f) + (SCALE * SCALE))); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * (TNum.One / (TNum.Pi * SCALE)) * ((SCALE * SCALE) / (TNum.Pow(x - MEDIAN, TWO) + (SCALE * SCALE))); } \ No newline at end of file diff --git a/FastRng/Distributions/ChiSquareK1.cs b/FastRng/Distributions/ChiSquareK1.cs index cffe2f3..de626e5 100644 --- a/FastRng/Distributions/ChiSquareK1.cs +++ b/FastRng/Distributions/ChiSquareK1.cs @@ -1,26 +1,28 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class ChiSquareK1 : Distribution +public sealed class ChiSquareK1 : Distribution where TNum : IFloatingPointIeee754 { - private const float K = 1.0f; - private const float K_HALF = K * 0.5f; - private const float K_HALF_MINUS_ONE = K_HALF - 1.0f; - private const float CONSTANT = 0.252f; + private static readonly TNum HALF = TNum.CreateChecked(0.5f); + private static readonly TNum TWO = TNum.CreateChecked(2f); + private static readonly TNum K = TNum.One; + private static readonly TNum K_HALF = K * HALF; + private static readonly TNum K_HALF_MINUS_ONE = K_HALF - TNum.One; + private static readonly TNum CONSTANT = TNum.CreateChecked(0.252f); - private static readonly float DIVISOR; + private static readonly TNum DIVISOR; static ChiSquareK1() { - var twoToTheKHalf = MathF.Pow(2f, K_HALF); - var gammaKHalf = MathTools.Gamma(K_HALF); + var twoToTheKHalf = TNum.Pow(TWO, K_HALF); + var gammaKHalf = FloatingPointMathTools.Gamma(K_HALF); DIVISOR = twoToTheKHalf * gammaKHalf; } - public ChiSquareK1(IRandom rng) : base(rng) + public ChiSquareK1(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * ((TNum.Pow(x, K_HALF_MINUS_ONE) * TNum.Exp(-x * HALF)) / DIVISOR); } \ No newline at end of file diff --git a/FastRng/Distributions/ChiSquareK10.cs b/FastRng/Distributions/ChiSquareK10.cs index 12f21ee..169651d 100644 --- a/FastRng/Distributions/ChiSquareK10.cs +++ b/FastRng/Distributions/ChiSquareK10.cs @@ -1,26 +1,28 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class ChiSquareK10 : Distribution +public sealed class ChiSquareK10 : Distribution where TNum : IFloatingPointIeee754 { - private const float K = 10.0f; - private const float K_HALF = K * 0.5f; - private const float K_HALF_MINUS_ONE = K_HALF - 1.0f; - private const float CONSTANT = 0.252f; + private static readonly TNum HALF = TNum.CreateChecked(0.5f); + private static readonly TNum TWO = TNum.CreateChecked(2f); + private static readonly TNum K = TNum.CreateChecked(10.0f); + private static readonly TNum K_HALF = K * HALF; + private static readonly TNum K_HALF_MINUS_ONE = K_HALF - TNum.One; + private static readonly TNum CONSTANT = TNum.CreateChecked(0.252f); - private static readonly float DIVISOR; + private static readonly TNum DIVISOR; static ChiSquareK10() { - var twoToTheKHalf = MathF.Pow(2f, K_HALF); - var gammaKHalf = MathTools.Gamma(K_HALF); + var twoToTheKHalf = TNum.Pow(TWO, K_HALF); + var gammaKHalf = FloatingPointMathTools.Gamma(K_HALF); DIVISOR = twoToTheKHalf * gammaKHalf; } - public ChiSquareK10(IRandom rng) : base(rng) + public ChiSquareK10(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * ((TNum.Pow(x, K_HALF_MINUS_ONE) * TNum.Exp(-x * HALF)) / DIVISOR); } \ No newline at end of file diff --git a/FastRng/Distributions/ChiSquareK4.cs b/FastRng/Distributions/ChiSquareK4.cs index b4d0884..263e459 100644 --- a/FastRng/Distributions/ChiSquareK4.cs +++ b/FastRng/Distributions/ChiSquareK4.cs @@ -1,26 +1,28 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class ChiSquareK4 : Distribution +public sealed class ChiSquareK4 : Distribution where TNum : IFloatingPointIeee754 { - private const float K = 4.0f; - private const float K_HALF = K * 0.5f; - private const float K_HALF_MINUS_ONE = K_HALF - 1.0f; - private const float CONSTANT = 0.252f; + private static readonly TNum HALF = TNum.CreateChecked(0.5f); + private static readonly TNum TWO = TNum.CreateChecked(2f); + private static readonly TNum K = TNum.CreateChecked(4f); + private static readonly TNum K_HALF = K * HALF; + private static readonly TNum K_HALF_MINUS_ONE = K_HALF - TNum.One; + private static readonly TNum CONSTANT = TNum.CreateChecked(0.252f); - private static readonly float DIVISOR; + private static readonly TNum DIVISOR; static ChiSquareK4() { - var twoToTheKHalf = MathF.Pow(2, K_HALF); - var gammaKHalf = MathTools.Gamma(K_HALF); + var twoToTheKHalf = TNum.Pow(TWO, K_HALF); + var gammaKHalf = FloatingPointMathTools.Gamma(K_HALF); DIVISOR = twoToTheKHalf * gammaKHalf; } - public ChiSquareK4(IRandom rng) : base(rng) + public ChiSquareK4(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * ((TNum.Pow(x, K_HALF_MINUS_ONE) * TNum.Exp(-x * HALF)) / DIVISOR); } \ No newline at end of file diff --git a/FastRng/Distributions/Distribution.cs b/FastRng/Distributions/Distribution.cs index 7b12978..bdd2cc3 100644 --- a/FastRng/Distributions/Distribution.cs +++ b/FastRng/Distributions/Distribution.cs @@ -1,24 +1,25 @@ using System; +using System.Numerics; using System.Threading; using System.Threading.Tasks; namespace FastRng.Distributions; -public abstract class Distribution : IDistribution +public abstract class Distribution : IDistribution where TNum : IFloatingPointIeee754 { - private readonly ShapeFitter fitter; + private readonly ShapeFitter fitter; - protected Distribution(IRandom rng) + protected Distribution(IRandom rng) { if (rng == null) - throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed."); + throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed."); - this.fitter = new ShapeFitter(this.ShapeFunction, rng, 100); + this.fitter = new ShapeFitter(this.ShapeFunction, rng, 100); } - private protected abstract float ShapeFunction(float x); + private protected abstract TNum ShapeFunction(TNum x); - public async ValueTask GetDistributedValue(CancellationToken token = default) => await this.fitter.NextNumber(token); + public async ValueTask GetDistributedValue(CancellationToken token = default) => await this.fitter.NextNumber(token); public async ValueTask NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default) { @@ -28,7 +29,7 @@ public abstract class Distribution : IDistribution var range = rangeEnd - rangeStart; var distributedValue = await this.GetDistributedValue(cancel); - return (uint) ((distributedValue * range) + rangeStart); + return (uint) ((float.CreateChecked(distributedValue) * range) + rangeStart); } public async ValueTask NextNumber(ulong rangeStart, ulong rangeEnd, CancellationToken cancel = default) @@ -39,10 +40,10 @@ public abstract class Distribution : IDistribution var range = rangeEnd - rangeStart; var distributedValue = await this.GetDistributedValue(cancel); - return (ulong) ((distributedValue * range) + rangeStart); + return (ulong) ((double.CreateChecked(distributedValue) * range) + rangeStart); } - public async ValueTask NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default) + public async ValueTask NextNumber(TNum rangeStart, TNum rangeEnd, CancellationToken cancel = default) { // Swap the values if the range start is greater than the range end: if (rangeStart > rangeEnd) @@ -53,9 +54,9 @@ public abstract class Distribution : IDistribution return (distributedValue * range) + rangeStart; } - public async ValueTask NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0f, 1.0f, cancel); + public async ValueTask NextNumber(CancellationToken cancel = default) => await this.NextNumber(TNum.Zero, TNum.One, cancel); - public async ValueTask HasDecisionBeenMade(float above, float below = 1, CancellationToken cancel = default) + public async ValueTask HasDecisionBeenMade(TNum above, TNum below, CancellationToken cancel = default) { var number = await this.NextNumber(cancel); return number > above && number < below; diff --git a/FastRng/Distributions/ExponentialLa10.cs b/FastRng/Distributions/ExponentialLa10.cs index c84561f..8002bcc 100644 --- a/FastRng/Distributions/ExponentialLa10.cs +++ b/FastRng/Distributions/ExponentialLa10.cs @@ -1,15 +1,15 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class ExponentialLa10 : Distribution +public sealed class ExponentialLa10 : Distribution where TNum : IFloatingPointIeee754 { - private const float LAMBDA = 10.0f; - private const float CONSTANT = 0.1106f; + private static readonly TNum LAMBDA = TNum.CreateChecked(10.0f); + private static readonly TNum CONSTANT = TNum.CreateChecked(0.1106f); - public ExponentialLa10(IRandom rng) : base(rng) + public ExponentialLa10(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * LAMBDA * TNum.Exp(-LAMBDA * x); } \ No newline at end of file diff --git a/FastRng/Distributions/ExponentialLa5.cs b/FastRng/Distributions/ExponentialLa5.cs index ddde778..c48eb2c 100644 --- a/FastRng/Distributions/ExponentialLa5.cs +++ b/FastRng/Distributions/ExponentialLa5.cs @@ -1,15 +1,15 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class ExponentialLa5 : Distribution +public sealed class ExponentialLa5 : Distribution where TNum : IFloatingPointIeee754 { - private const float LAMBDA = 5.0f; - private const float CONSTANT = 0.2103f; + private static readonly TNum LAMBDA = TNum.CreateChecked(5.0f); + private static readonly TNum CONSTANT = TNum.CreateChecked(0.2103f); - public ExponentialLa5(IRandom rng) : base(rng) + public ExponentialLa5(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * LAMBDA * TNum.Exp(-LAMBDA * x); } \ No newline at end of file diff --git a/FastRng/Distributions/GammaA5B15.cs b/FastRng/Distributions/GammaA5B15.cs index 444b074..957d409 100644 --- a/FastRng/Distributions/GammaA5B15.cs +++ b/FastRng/Distributions/GammaA5B15.cs @@ -1,25 +1,25 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class GammaA5B15 : Distribution +public sealed class GammaA5B15 : Distribution where TNum : IFloatingPointIeee754 { - private const float ALPHA = 5.0f; - private const float BETA = 15.0f; - private const float CONSTANT = 0.341344210715475f; + private static readonly TNum ALPHA = TNum.CreateChecked(5.0f); + private static readonly TNum BETA = TNum.CreateChecked(15.0f); + private static readonly TNum CONSTANT = TNum.CreateChecked(0.341344210715475f); - private static readonly float GAMMA_ALPHA; - private static readonly float BETA_TO_THE_ALPHA; + private static readonly TNum GAMMA_ALPHA; + private static readonly TNum BETA_TO_THE_ALPHA; static GammaA5B15() { - GAMMA_ALPHA = MathTools.Gamma(ALPHA); - BETA_TO_THE_ALPHA = MathF.Pow(BETA, ALPHA); + GAMMA_ALPHA = FloatingPointMathTools.Gamma(ALPHA); + BETA_TO_THE_ALPHA = TNum.Pow(BETA, ALPHA); } - public GammaA5B15(IRandom rng) : base(rng) + public GammaA5B15(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * ((BETA_TO_THE_ALPHA * MathF.Pow(x, ALPHA - 1.0f) * MathF.Exp(-BETA * x)) / GAMMA_ALPHA); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * ((BETA_TO_THE_ALPHA * TNum.Pow(x, ALPHA - TNum.One) * TNum.Exp(-BETA * x)) / GAMMA_ALPHA); } \ No newline at end of file diff --git a/FastRng/Distributions/IDistribution.cs b/FastRng/Distributions/IDistribution.cs index 5f254c2..8c0abb3 100644 --- a/FastRng/Distributions/IDistribution.cs +++ b/FastRng/Distributions/IDistribution.cs @@ -1,19 +1,20 @@ +using System.Numerics; using System.Threading; using System.Threading.Tasks; namespace FastRng.Distributions; -public interface IDistribution +public interface IDistribution where TNum : IFloatingPointIeee754 { - public ValueTask GetDistributedValue(CancellationToken token); + public ValueTask GetDistributedValue(CancellationToken token); public ValueTask NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default); public ValueTask NextNumber(ulong rangeStart, ulong rangeEnd, CancellationToken cancel = default); - public ValueTask NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default); + public ValueTask NextNumber(TNum rangeStart, TNum rangeEnd, CancellationToken cancel = default); - public ValueTask NextNumber(CancellationToken cancel = default); + public ValueTask NextNumber(CancellationToken cancel = default); - public ValueTask HasDecisionBeenMade(float above, float below = 1.0f, CancellationToken cancel = default); + public ValueTask HasDecisionBeenMade(TNum above, TNum below, CancellationToken cancel = default); } \ No newline at end of file diff --git a/FastRng/Distributions/InverseExponentialLa10.cs b/FastRng/Distributions/InverseExponentialLa10.cs index 0fce9f2..da6bc7d 100644 --- a/FastRng/Distributions/InverseExponentialLa10.cs +++ b/FastRng/Distributions/InverseExponentialLa10.cs @@ -1,15 +1,15 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class InverseExponentialLa10 : Distribution +public sealed class InverseExponentialLa10 : Distribution where TNum : IFloatingPointIeee754 { - private const float LAMBDA = 10.0f; - private const float CONSTANT = 4.539992976248453e-06f; + private static readonly TNum LAMBDA = TNum.CreateChecked(10.0f); + private static readonly TNum CONSTANT = TNum.CreateChecked(4.539992976248453e-06f); - public InverseExponentialLa10(IRandom rng) : base(rng) + public InverseExponentialLa10(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * LAMBDA * TNum.Exp(LAMBDA * x); } \ No newline at end of file diff --git a/FastRng/Distributions/InverseExponentialLa5.cs b/FastRng/Distributions/InverseExponentialLa5.cs index 63b5e9c..817beef 100644 --- a/FastRng/Distributions/InverseExponentialLa5.cs +++ b/FastRng/Distributions/InverseExponentialLa5.cs @@ -1,15 +1,15 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class InverseExponentialLa5 : Distribution +public sealed class InverseExponentialLa5 : Distribution where TNum : IFloatingPointIeee754 { - private const float LAMBDA = 5.0f; - private const float CONSTANT = 0.001347589399817f; + private static readonly TNum LAMBDA = TNum.CreateChecked(5.0f); + private static readonly TNum CONSTANT = TNum.CreateChecked(0.001347589399817f); - public InverseExponentialLa5(IRandom rng) : base(rng) + public InverseExponentialLa5(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * LAMBDA * TNum.Exp(LAMBDA * x); } \ No newline at end of file diff --git a/FastRng/Distributions/InverseGammaA3B05.cs b/FastRng/Distributions/InverseGammaA3B05.cs index 4c49d83..b00b0e3 100644 --- a/FastRng/Distributions/InverseGammaA3B05.cs +++ b/FastRng/Distributions/InverseGammaA3B05.cs @@ -1,26 +1,26 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class InverseGammaA3B05 : Distribution +public sealed class InverseGammaA3B05 : Distribution where TNum : IFloatingPointIeee754 { - private const float ALPHA = 3.0f; - private const float BETA = 0.5f; - private const float CONSTANT = 0.213922656884911f; + private static readonly TNum ALPHA = TNum.CreateChecked(3.0f); + private static readonly TNum BETA = TNum.CreateChecked(0.5f); + private static readonly TNum CONSTANT = TNum.CreateChecked(0.213922656884911f); - private static readonly float FACTOR_LEFT; + private static readonly TNum FACTOR_LEFT; static InverseGammaA3B05() { - var gammaAlpha = MathTools.Gamma(ALPHA); - var betaToTheAlpha = MathF.Pow(BETA, ALPHA); + var gammaAlpha = FloatingPointMathTools.Gamma(ALPHA); + var betaToTheAlpha = TNum.Pow(BETA, ALPHA); FACTOR_LEFT = CONSTANT * (betaToTheAlpha / gammaAlpha); } - public InverseGammaA3B05(IRandom rng) : base(rng) + public InverseGammaA3B05(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Pow(x, -ALPHA - 1.0f) * MathF.Exp(-BETA / x); + private protected override TNum ShapeFunction(TNum x) => FACTOR_LEFT * TNum.Pow(x, -ALPHA - TNum.One) * TNum.Exp(-BETA / x); } \ No newline at end of file diff --git a/FastRng/Distributions/LaplaceB01M0.cs b/FastRng/Distributions/LaplaceB01M0.cs index 50afef0..8e5dca7 100644 --- a/FastRng/Distributions/LaplaceB01M0.cs +++ b/FastRng/Distributions/LaplaceB01M0.cs @@ -1,23 +1,24 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class LaplaceB01M0 : Distribution +public sealed class LaplaceB01M0 : Distribution where TNum : IFloatingPointIeee754 { - private const float B = 0.1f; - private const float MU = 0.0f; - private const float CONSTANT = 0.221034183615129f; + private static readonly TNum TWO = TNum.CreateChecked(2.0f); + private static readonly TNum B = TNum.CreateChecked(0.1f); + private static readonly TNum MU = TNum.Zero; + private static readonly TNum CONSTANT = TNum.CreateChecked(0.221034183615129f); - private static readonly float FACTOR_LEFT; + private static readonly TNum FACTOR_LEFT; static LaplaceB01M0() { - FACTOR_LEFT = CONSTANT / (2.0f * B); + FACTOR_LEFT = CONSTANT / (TWO * B); } - public LaplaceB01M0(IRandom rng) : base(rng) + public LaplaceB01M0(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B); + private protected override TNum ShapeFunction(TNum x) => FACTOR_LEFT * TNum.Exp(-TNum.Abs(x - MU) / B); } \ No newline at end of file diff --git a/FastRng/Distributions/LaplaceB01M05.cs b/FastRng/Distributions/LaplaceB01M05.cs index 4a219dd..5849316 100644 --- a/FastRng/Distributions/LaplaceB01M05.cs +++ b/FastRng/Distributions/LaplaceB01M05.cs @@ -1,23 +1,24 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class LaplaceB01M05 : Distribution +public sealed class LaplaceB01M05 : Distribution where TNum : IFloatingPointIeee754 { - private const float B = 0.1f; - private const float MU = 0.5f; - private const float CONSTANT = 0.2f; + private static readonly TNum TWO = TNum.CreateChecked(2.0f); + private static readonly TNum B = TNum.CreateChecked(0.1f); + private static readonly TNum MU = TNum.CreateChecked(0.5f); + private static readonly TNum CONSTANT = TNum.CreateChecked(0.2f); - private static readonly float FACTOR_LEFT; + private static readonly TNum FACTOR_LEFT; static LaplaceB01M05() { - FACTOR_LEFT = CONSTANT / (2.0f * B); + FACTOR_LEFT = CONSTANT / (TWO * B); } - public LaplaceB01M05(IRandom rng) : base(rng) + public LaplaceB01M05(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B); + private protected override TNum ShapeFunction(TNum x) => FACTOR_LEFT * TNum.Exp(-TNum.Abs(x - MU) / B); } \ No newline at end of file diff --git a/FastRng/Distributions/LogNormalS1M0.cs b/FastRng/Distributions/LogNormalS1M0.cs index d6d538e..1900ad4 100644 --- a/FastRng/Distributions/LogNormalS1M0.cs +++ b/FastRng/Distributions/LogNormalS1M0.cs @@ -1,23 +1,24 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class LogNormalS1M0 : Distribution +public sealed class LogNormalS1M0 : Distribution where TNum : IFloatingPointIeee754 { - private const float SIGMA = 1.0f; - private const float MU = 0.0f; - private const float CONSTANT = 1.51998658387455f; + private static readonly TNum TWO = TNum.CreateChecked(2f); + private static readonly TNum SIGMA = TNum.One; + private static readonly TNum MU = TNum.Zero; + private static readonly TNum CONSTANT = TNum.CreateChecked(1.51998658387455f); - private static readonly float FACTOR; + private static readonly TNum FACTOR; static LogNormalS1M0() { - FACTOR = SIGMA * MathF.Sqrt(2f * MathF.PI); + FACTOR = SIGMA * TNum.Sqrt(TWO * TNum.Pi); } - public LogNormalS1M0(IRandom rng) : base(rng) + public LogNormalS1M0(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => (CONSTANT / (x * FACTOR)) * MathF.Exp( -(MathF.Pow(MathF.Log(x) - MU, 2f) / (2f * MathF.Pow(SIGMA, 2f)))); + private protected override TNum ShapeFunction(TNum x) => (CONSTANT / (x * FACTOR)) * TNum.Exp( -(TNum.Pow(TNum.Log(x) - MU, TWO) / (TWO * TNum.Pow(SIGMA, TWO)))); } \ No newline at end of file diff --git a/FastRng/Distributions/NormalS02M05.cs b/FastRng/Distributions/NormalS02M05.cs index 5cb0168..93cf3c3 100644 --- a/FastRng/Distributions/NormalS02M05.cs +++ b/FastRng/Distributions/NormalS02M05.cs @@ -1,16 +1,18 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class NormalS02M05 : Distribution +public sealed class NormalS02M05 : Distribution where TNum : IFloatingPointIeee754 { - private const float SQRT_2_PI = 2.506628275f; - private const float STD_DEV = 0.2f; - private const float MEAN = 0.5f; + private static readonly TNum TWO = TNum.CreateChecked(2f); + private static readonly TNum NEGATIVE_HALF = TNum.CreateChecked(-0.5f); + private static readonly TNum SQRT_2_PI = TNum.CreateChecked(2.506628275f); + private static readonly TNum STD_DEV = TNum.CreateChecked(0.2f); + private static readonly TNum MEAN = TNum.CreateChecked(0.5f); - public NormalS02M05(IRandom rng) : base(rng) + public NormalS02M05(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => 1.0f / (STD_DEV * SQRT_2_PI) * MathF.Exp(-0.5f * MathF.Pow((x - MEAN) / STD_DEV, 2.0f)); + private protected override TNum ShapeFunction(TNum x) => TNum.One / (STD_DEV * SQRT_2_PI) * TNum.Exp(NEGATIVE_HALF * TNum.Pow((x - MEAN) / STD_DEV, TWO)); } \ No newline at end of file diff --git a/FastRng/Distributions/StudentTNu1.cs b/FastRng/Distributions/StudentTNu1.cs index cc64255..d349f10 100644 --- a/FastRng/Distributions/StudentTNu1.cs +++ b/FastRng/Distributions/StudentTNu1.cs @@ -1,28 +1,30 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class StudentTNu1 : Distribution +public sealed class StudentTNu1 : Distribution where TNum : IFloatingPointIeee754 { - private const float NU = 1.0f; - private const float START = 0.0f; - private const float COMPRESS = 1.0f; - private const float CONSTANT = 3.14190548592729f; + private static readonly TNum HALF = TNum.CreateChecked(0.5f); + private static readonly TNum TWO = TNum.CreateChecked(2f); + private static readonly TNum NU = TNum.One; + private static readonly TNum START = TNum.Zero; + private static readonly TNum COMPRESS = TNum.One; + private static readonly TNum CONSTANT = TNum.CreateChecked(3.14190548592729f); - private static readonly float DIVIDEND; - private static readonly float DIVISOR; - private static readonly float EXPONENT; + private static readonly TNum DIVIDEND; + private static readonly TNum DIVISOR; + private static readonly TNum EXPONENT; static StudentTNu1() { - DIVIDEND = MathTools.Gamma((NU + 1.0f) * 0.5f); - DIVISOR = MathF.Sqrt(NU * MathF.PI) * MathTools.Gamma(NU * 0.5f); - EXPONENT = -((NU + 1.0f) * 0.5f); + DIVIDEND = FloatingPointMathTools.Gamma((NU + TNum.One) * HALF); + DIVISOR = TNum.Sqrt(NU * TNum.Pi) * FloatingPointMathTools.Gamma(NU * HALF); + EXPONENT = -((NU + TNum.One) * HALF); } - public StudentTNu1(IRandom rng) : base(rng) + public StudentTNu1(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow((DIVIDEND / DIVISOR) * MathF.Pow(1.0f + MathF.Pow(START + x * COMPRESS, 2f) / NU, EXPONENT), COMPRESS); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * TNum.Pow((DIVIDEND / DIVISOR) * TNum.Pow( TNum.One + TNum.Pow(START + x * COMPRESS, TWO) / NU, EXPONENT), COMPRESS); } \ No newline at end of file diff --git a/FastRng/Distributions/Uniform.cs b/FastRng/Distributions/Uniform.cs index 2cd7e55..b03e36a 100644 --- a/FastRng/Distributions/Uniform.cs +++ b/FastRng/Distributions/Uniform.cs @@ -1,19 +1,20 @@ using System; +using System.Numerics; using System.Threading; using System.Threading.Tasks; namespace FastRng.Distributions; -public sealed class Uniform : IDistribution +public sealed class Uniform : IDistribution where TNum : IFloatingPointIeee754 { - private readonly IRandom rng; + private readonly IRandom rng; - public Uniform(IRandom rng) + public Uniform(IRandom rng) { - this.rng = rng ?? throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed."); + this.rng = rng ?? throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed."); } - public async ValueTask GetDistributedValue(CancellationToken token = default) => await this.rng.GetUniform(token); + public async ValueTask GetDistributedValue(CancellationToken token = default) => await this.rng.GetUniform(token); public async ValueTask NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default) { @@ -23,7 +24,7 @@ public sealed class Uniform : IDistribution var range = rangeEnd - rangeStart; var distributedValue = await this.GetDistributedValue(cancel); - return (uint) ((distributedValue * range) + rangeStart); + return (uint) ((float.CreateChecked(distributedValue) * range) + rangeStart); } public async ValueTask NextNumber(ulong rangeStart, ulong rangeEnd, CancellationToken cancel = default) @@ -34,10 +35,10 @@ public sealed class Uniform : IDistribution var range = rangeEnd - rangeStart; var distributedValue = await this.GetDistributedValue(cancel); - return (ulong) ((distributedValue * range) + rangeStart); + return (ulong) ((double.CreateChecked(distributedValue) * range) + rangeStart); } - public async ValueTask NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default) + public async ValueTask NextNumber(TNum rangeStart, TNum rangeEnd, CancellationToken cancel = default) { // Swap the values if the range start is greater than the range end: if (rangeStart > rangeEnd) @@ -48,9 +49,9 @@ public sealed class Uniform : IDistribution return (distributedValue * range) + rangeStart; } - public async ValueTask NextNumber(CancellationToken cancel = default) => await this.NextNumber(0.0f, 1.0f, cancel); + public async ValueTask NextNumber(CancellationToken cancel = default) => await this.NextNumber(TNum.Zero, TNum.One, cancel); - public async ValueTask HasDecisionBeenMade(float above, float below = 1, CancellationToken cancel = default) + public async ValueTask HasDecisionBeenMade(TNum above, TNum below, CancellationToken cancel = default) { var number = await this.NextNumber(cancel); return number > above && number < below; diff --git a/FastRng/Distributions/WeibullK05La1.cs b/FastRng/Distributions/WeibullK05La1.cs index ef7df03..598bf8a 100644 --- a/FastRng/Distributions/WeibullK05La1.cs +++ b/FastRng/Distributions/WeibullK05La1.cs @@ -1,16 +1,16 @@ -using System; +using System.Numerics; namespace FastRng.Distributions; -public sealed class WeibullK05La1 : Distribution +public sealed class WeibullK05La1 : Distribution where TNum : IFloatingPointIeee754 { - private const float K = 0.5f; - private const float LAMBDA = 1.0f; - private const float CONSTANT = 0.221034183615129f; + private static readonly TNum K = TNum.CreateChecked(0.5f); + private static readonly TNum LAMBDA = TNum.One; + private static readonly TNum CONSTANT = TNum.CreateChecked(0.221034183615129f); - public WeibullK05La1(IRandom rng) : base(rng) + public WeibullK05La1(IRandom rng) : base(rng) { } - private protected override float ShapeFunction(float x) => CONSTANT * ( (K / LAMBDA) * MathF.Pow(x / LAMBDA, K - 1.0f) * MathF.Exp(-MathF.Pow(x/LAMBDA, K))); + private protected override TNum ShapeFunction(TNum x) => CONSTANT * ( (K / LAMBDA) * TNum.Pow(x / LAMBDA, K - TNum.One) * TNum.Exp(-TNum.Pow(x/LAMBDA, K))); } \ No newline at end of file diff --git a/FastRng/FloatingPointMathTools.cs b/FastRng/FloatingPointMathTools.cs new file mode 100644 index 0000000..1696a94 --- /dev/null +++ b/FastRng/FloatingPointMathTools.cs @@ -0,0 +1,63 @@ +using System; +using System.Numerics; + +namespace FastRng; + +/// +/// Provides some mathematical function, which are not available within in .NET itself. +/// +public static class FloatingPointMathTools where TNum : IFloatingPointIeee754, IAdditionOperators +{ + private static readonly TNum SQRT_2 = TNum.Sqrt(TNum.One + TNum.One); + private static readonly TNum SQRT_PI = TNum.Sqrt(TNum.Pi); + + // Source: http://rosettacode.org/wiki/Gamma_function#Go + private static readonly TNum F1 = TNum.CreateChecked(6.5f); + private static readonly TNum A1 = TNum.CreateChecked(.99999999999980993f); + private static readonly TNum A2 = TNum.CreateChecked(676.5203681218851f); + private static readonly TNum A3 = TNum.CreateChecked(1259.1392167224028f); + private static readonly TNum A4 = TNum.CreateChecked(771.32342877765313f); + private static readonly TNum A5 = TNum.CreateChecked(176.61502916214059f); + private static readonly TNum A6 = TNum.CreateChecked(12.507343278686905f); + private static readonly TNum A7 = TNum.CreateChecked(.13857109526572012f); + private static readonly TNum A8 = TNum.CreateChecked(9.9843695780195716e-6f); + private static readonly TNum A9 = TNum.CreateChecked(1.5056327351493116e-7f); + + private static readonly TNum CONST1 = TNum.One; + private static readonly TNum CONST2 = CONST1 + TNum.One; + private static readonly TNum CONST3 = CONST2 + TNum.One; + private static readonly TNum CONST4 = CONST3 + TNum.One; + private static readonly TNum CONST5 = CONST4 + TNum.One; + private static readonly TNum CONST6 = CONST5 + TNum.One; + private static readonly TNum CONST7 = CONST6 + TNum.One; + + private static readonly TNum CONST_HALF = TNum.CreateChecked(0.5f); + + /// + /// The mathematical gamma function. + /// + /// The value for which you want calculate gamma. + public static TNum Gamma(TNum z) + { + // Source: http://rosettacode.org/wiki/Gamma_function#Go + + var t = z + F1; + var x = A1 + + A2 / z - + A3 / (z + CONST1) + + A4 / (z + CONST2) - + A5 / (z + CONST3) + + A6 / (z + CONST4) - + A7 / (z + CONST5) + + A8 / (z + CONST6) + + A9 / (z + CONST7); + + return SQRT_2 * SQRT_PI * TNum.Pow(t, z - CONST_HALF) * TNum.Exp(-t) * x; + } + + /// + /// The mathematical factorial function for floating-point numbers. + /// + /// The value, for which you want to know the factorial. + public static TNum Factorial(TNum x) => Gamma(x + CONST1); +} \ No newline at end of file diff --git a/FastRng/HugeInteger.cs b/FastRng/HugeInteger.cs deleted file mode 100644 index 561a20a..0000000 --- a/FastRng/HugeInteger.cs +++ /dev/null @@ -1,555 +0,0 @@ -using System; -using System.Globalization; -using System.Linq; -using System.Numerics; - -namespace FastRng; - -public struct HugeInteger : - IBinaryInteger>, - IComparisonOperators, TOtherNum, HugeInteger>, - IMultiplyOperators, TOtherNum, HugeInteger> - where TOtherNum : IBinaryInteger -{ - private ulong value = default; - - public HugeInteger(ulong value) => this.value = value; - - #region IBinaryInteger - - #region Implementation of IComparable - - /// - public int CompareTo(object obj) => this.value.CompareTo(obj); - - #endregion - - #region Implementation of IComparable - - /// - public int CompareTo(HugeInteger other) => this.value.CompareTo(other.value); - - #endregion - - #region Implementation of IEquatable - - /// - public bool Equals(HugeInteger other) => this.value.Equals(other.value); - - #endregion - - #region Implementation of IFormattable - - /// - public string ToString(string format, IFormatProvider formatProvider) => this.value.ToString(format, formatProvider); - - #endregion - - #region Implementation of IParsable - - /// - public static HugeInteger Parse(string s, IFormatProvider provider) => new(ulong.Parse(s, provider)); - - /// - public static bool TryParse(string s, IFormatProvider provider, out HugeInteger result) - { - if (ulong.TryParse(s, NumberStyles.Integer, provider, out var value)) - { - result = new HugeInteger(value); - return true; - } - - result = default; - return false; - } - - #endregion - - #region Implementation of ISpanFormattable - - /// - public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider provider) => this.value.TryFormat(destination, out charsWritten, format, provider); - - #endregion - - #region Implementation of ISpanParsable - - /// - public static HugeInteger Parse(ReadOnlySpan s, IFormatProvider provider) => new(ulong.Parse(s, provider)); - - /// - public static bool TryParse(ReadOnlySpan s, IFormatProvider provider, out HugeInteger result) - { - if (ulong.TryParse(s, NumberStyles.Integer, provider, out var value)) - { - result = new HugeInteger(value); - return true; - } - - result = default; - return false; - } - - #endregion - - #region Implementation of IAdditionOperators - - /// - public static HugeInteger operator +(HugeInteger left, HugeInteger right) => new(left.value + right.value); - - #endregion - - #region Implementation of IAdditiveIdentity - - /// - public static HugeInteger AdditiveIdentity => new(0); - - #endregion - - #region Implementation of IBitwiseOperators - - /// - public static HugeInteger operator &(HugeInteger left, HugeInteger right) => new(left.value & right.value); - - /// - public static HugeInteger operator |(HugeInteger left, HugeInteger right) => new(left.value | right.value); - - /// - public static HugeInteger operator ^(HugeInteger left, HugeInteger right) => new(left.value ^ right.value); - - /// - public static HugeInteger operator ~(HugeInteger value) => new(~value.value); - - #endregion - - #region Implementation of IEqualityOperators - - /// - public static bool operator ==(HugeInteger left, HugeInteger right) => left.value == right.value; - - /// - public static bool operator !=(HugeInteger left, HugeInteger right) => left.value != right.value; - - #endregion - - #region Implementation of IComparisonOperators - - /// - public static bool operator >(HugeInteger left, HugeInteger right) => left.value > right.value; - - /// - public static bool operator >=(HugeInteger left, HugeInteger right) => left.value >= right.value; - - /// - public static bool operator <(HugeInteger left, HugeInteger right) => left.value < right.value; - - /// - public static bool operator <=(HugeInteger left, HugeInteger right) => left.value <= right.value; - - #endregion - - #region Implementation of IDecrementOperators - - /// - public static HugeInteger operator --(HugeInteger value) - { - value.value--; - return value; - } - - #endregion - - #region Implementation of IDivisionOperators - - /// - public static HugeInteger operator /(HugeInteger left, HugeInteger right) => new(left.value / right.value); - - #endregion - - #region Implementation of IIncrementOperators - - /// - public static HugeInteger operator ++(HugeInteger value) - { - value.value++; - return value; - } - - #endregion - - #region Implementation of IModulusOperators - - /// - public static HugeInteger operator %(HugeInteger left, HugeInteger right) => new(left.value % right.value); - - #endregion - - #region Implementation of IMultiplicativeIdentity - - /// - public static HugeInteger MultiplicativeIdentity => new(1); - - #endregion - - #region Implementation of IMultiplyOperators - - /// - public static HugeInteger operator *(HugeInteger left, HugeInteger right) => new(left.value * right.value); - - #endregion - - #region Implementation of ISubtractionOperators - - /// - public static HugeInteger operator -(HugeInteger left, HugeInteger right) => new(left.value - right.value); - - #endregion - - #region Implementation of IUnaryNegationOperators - - /// - public static HugeInteger operator -(HugeInteger value) => throw new NotImplementedException(); - - #endregion - - #region Implementation of IUnaryPlusOperators - - /// - public static HugeInteger operator +(HugeInteger value) => throw new NotImplementedException(); - - #endregion - - #region Implementation of INumberBase - - /// - public static HugeInteger Abs(HugeInteger value) => value; - - /// - public static bool IsCanonical(HugeInteger value) => true; - - /// - public static bool IsComplexNumber(HugeInteger value) => false; - - /// - public static bool IsEvenInteger(HugeInteger value) => ulong.IsEvenInteger(value.value); - - /// - public static bool IsFinite(HugeInteger value) => true; - - /// - public static bool IsImaginaryNumber(HugeInteger value) => false; - - /// - public static bool IsInfinity(HugeInteger value) => false; - - /// - public static bool IsInteger(HugeInteger value) => true; - - /// - public static bool IsNaN(HugeInteger value) => false; - - /// - public static bool IsNegative(HugeInteger value) => false; - - /// - public static bool IsNegativeInfinity(HugeInteger value) => false; - - /// - public static bool IsNormal(HugeInteger value) => true; - - /// - public static bool IsOddInteger(HugeInteger value) => ulong.IsOddInteger(value.value); - - /// - public static bool IsPositive(HugeInteger value) => true; - - /// - public static bool IsPositiveInfinity(HugeInteger value) => false; - - /// - public static bool IsRealNumber(HugeInteger value) => true; - - /// - public static bool IsSubnormal(HugeInteger value) => false; - - /// - public static bool IsZero(HugeInteger value) => value.value == 0; - - /// - public static HugeInteger MaxMagnitude(HugeInteger x, HugeInteger y) => x.value > y.value ? x : y; - - /// - public static HugeInteger MaxMagnitudeNumber(HugeInteger x, HugeInteger y) => x.value > y.value ? x : y; - - /// - public static HugeInteger MinMagnitude(HugeInteger x, HugeInteger y) => x.value < y.value ? x : y; - - /// - public static HugeInteger MinMagnitudeNumber(HugeInteger x, HugeInteger y) => x.value < y.value ? x : y; - - /// - public static HugeInteger Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider provider) => new(ulong.Parse(s, style, provider)); - - /// - public static HugeInteger Parse(string s, NumberStyles style, IFormatProvider provider) => new(ulong.Parse(s, style, provider)); - - /// - public static bool TryConvertFromChecked(TOther value, out HugeInteger result) where TOther : INumberBase - { - result = new HugeInteger(ulong.CreateChecked(value)); - return true; - } - - /// - public static bool TryConvertFromSaturating(TOther value, out HugeInteger result) where TOther : INumberBase - { - result = new HugeInteger(ulong.CreateSaturating(value)); - return true; - } - - /// - public static bool TryConvertFromTruncating(TOther value, out HugeInteger result) where TOther : INumberBase - { - result = new HugeInteger(ulong.CreateTruncating(value)); - return true; - } - - /// - public static bool TryConvertToChecked(HugeInteger value, out TOther result) where TOther : INumberBase - { - result = TOther.CreateChecked(value.value); - return true; - } - - /// - public static bool TryConvertToSaturating(HugeInteger value, out TOther result) where TOther : INumberBase - { - result = TOther.CreateSaturating(value.value); - return true; - } - - /// - public static bool TryConvertToTruncating(HugeInteger value, out TOther result) where TOther : INumberBase - { - result = TOther.CreateTruncating(value.value); - return true; - } - - /// - public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider provider, out HugeInteger result) - { - var state = ulong.TryParse(s, style, provider, out var value); - if(state) - result = new HugeInteger(value); - else - result = default; - - return state; - } - - /// - public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out HugeInteger result) - { - var state = ulong.TryParse(s, style, provider, out var value); - if(state) - result = new HugeInteger(value); - else - result = default; - - return state; - } - - /// - public static HugeInteger One => new(1); - - /// - public static int Radix => 2; - - /// - public static HugeInteger Zero => new(0); - - #endregion - - #region Implementation of IBinaryNumber - - /// - public static bool IsPow2(HugeInteger value) => ulong.IsPow2(value.value); - - /// - public static HugeInteger Log2(HugeInteger value) => new(ulong.Log2(value.value)); - - #endregion - - #region Implementation of IShiftOperators - - /// - public static HugeInteger operator <<(HugeInteger value, int shiftAmount) => new(value.value << shiftAmount); - - /// - public static HugeInteger operator >> (HugeInteger value, int shiftAmount) => new(value.value >> shiftAmount); - - /// - public static HugeInteger operator >>> (HugeInteger value, int shiftAmount) => new(value.value >>> shiftAmount); - - #endregion - - #region Implementation of IBinaryInteger - - /// - public int GetByteCount() => sizeof(ulong); - - /// - public int GetShortestBitLength() => (sizeof(ulong) * 8) - BitOperations.LeadingZeroCount(this.value); - - /// - public static HugeInteger PopCount(HugeInteger value) => new((ulong)BitOperations.PopCount(value.value)); - - /// - public static HugeInteger TrailingZeroCount(HugeInteger value) => new((ulong)BitOperations.TrailingZeroCount(value.value)); - - /// - public static bool TryReadBigEndian(ReadOnlySpan source, bool isUnsigned, out HugeInteger value) - { - if (!isUnsigned) - { - value = default; - return false; - } - - if(source.Length != sizeof(ulong)) - { - value = default; - return false; - } - - var sourceBytes = source.ToArray(); - if (BitConverter.IsLittleEndian) - sourceBytes = sourceBytes.Reverse().ToArray(); - - value = new HugeInteger(BitConverter.ToUInt64(sourceBytes)); - return true; - } - - /// - public static bool TryReadLittleEndian(ReadOnlySpan source, bool isUnsigned, out HugeInteger value) - { - if (!isUnsigned) - { - value = default; - return false; - } - - if(source.Length != sizeof(ulong)) - { - value = default; - return false; - } - - var sourceBytes = source.ToArray(); - if (!BitConverter.IsLittleEndian) - sourceBytes = sourceBytes.Reverse().ToArray(); - - value = new HugeInteger(BitConverter.ToUInt64(sourceBytes)); - return true; - } - - /// - public bool TryWriteBigEndian(Span destination, out int bytesWritten) - { - var bytes = BitConverter.GetBytes(this.value); - if (BitConverter.IsLittleEndian) - bytes = bytes.Reverse().ToArray(); - - bytes.CopyTo(destination); - bytesWritten = bytes.Length; - return true; - } - - /// - public bool TryWriteLittleEndian(Span destination, out int bytesWritten) - { - var bytes = BitConverter.GetBytes(this.value); - if (!BitConverter.IsLittleEndian) - bytes = bytes.Reverse().ToArray(); - - bytes.CopyTo(destination); - bytesWritten = bytes.Length; - return true; - } - - #endregion - - #endregion - - #region Necessary extra operators - - #region Implementation of IEqualityOperators,TOtherNum,HugeInteger> - - /// - public static HugeInteger operator ==(HugeInteger left, TOtherNum right) - { - return left == right; - } - - /// - public static HugeInteger operator !=(HugeInteger left, TOtherNum right) - { - return left != right; - } - - #endregion - - #region Implementation of IComparisonOperators,TOtherNum,HugeInteger> - - /// - public static HugeInteger operator >(HugeInteger left, TOtherNum right) - { - return left > right; - } - - /// - public static HugeInteger operator >=(HugeInteger left, TOtherNum right) - { - return left >= right; - } - - /// - public static HugeInteger operator <(HugeInteger left, TOtherNum right) - { - return left < right; - } - - /// - public static HugeInteger operator <=(HugeInteger left, TOtherNum right) - { - return left <= right; - } - - #endregion - - #region Implementation of IMultiplyOperators,TOtherNum,HugeInteger> - - /// - public static HugeInteger operator *(HugeInteger left, TOtherNum right) - { - // Would work, but TOtherNum might not be able to hold the result! Thus, we cannot convert - // left to TOtherNum, and we cannot convert right to HugeInteger. - // return new HugeInteger(ulong.CreateSaturating(TOtherNum.CreateSaturating(left.value) * right)); - - return left * right; - } - - #endregion - - #endregion - - /// - /// Converts a ulong to a HugeInteger. - /// - public static implicit operator HugeInteger(ulong value) => new(value); - - /// - /// Converts a HugeInteger to a ulong. - /// - public static implicit operator ulong(HugeInteger value) => value.value; -} \ No newline at end of file diff --git a/FastRng/IRandom.cs b/FastRng/IRandom.cs index 489363c..430c25a 100644 --- a/FastRng/IRandom.cs +++ b/FastRng/IRandom.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using System.Threading; using System.Threading.Tasks; @@ -7,7 +8,7 @@ namespace FastRng; /// /// Interface for random number generators. /// -public interface IRandom : IDisposable +public interface IRandom : IDisposable where TNum : IFloatingPointIeee754 { /// /// Returns a uniform distributed pseudo-random number from the interval (0,1]. @@ -18,5 +19,5 @@ public interface IRandom : IDisposable /// by using multiple threads at the same time. /// /// An optional cancellation token. - public ValueTask GetUniform(CancellationToken cancel = default); + public ValueTask GetUniform(CancellationToken cancel = default); } \ No newline at end of file diff --git a/FastRng/IntegerMathTools.cs b/FastRng/IntegerMathTools.cs index d023729..e6cef21 100644 --- a/FastRng/IntegerMathTools.cs +++ b/FastRng/IntegerMathTools.cs @@ -1,27 +1,24 @@ using System; -using System.Numerics; namespace FastRng; /// /// Provides some mathematical function, which are not available within in .NET itself. /// -public static class IntegerMathTools where TNum : IBinaryInteger, IComparisonOperators, TNum, HugeInteger>, IMultiplyOperators, TNum, HugeInteger> +public static class IntegerMathTools { - private static readonly TNum CONST20 = TNum.CreateChecked(20); - /// /// The mathematical factorial function for integer numbers. /// /// The value, for which you want to know the factorial. /// Throws, when x is greater than 20. Due to limitations of 64bit ulong type. - public static ulong Factorial(TNum x) + public static ulong Factorial(uint x) { - if (x > CONST20) + if (x > 20) throw new ArgumentOutOfRangeException(nameof(x), $"Cannot compute {x}!, since ulong.max is 18_446_744_073_709_551_615."); - - var accumulator = new HugeInteger(1); - for (var factor = TNum.One; factor <= x; factor++) + + ulong accumulator = 1; + for (uint factor = 1; factor <= x; factor++) accumulator *= factor; return accumulator; diff --git a/FastRng/MathTools.cs b/FastRng/MathTools.cs deleted file mode 100644 index 3e6e0b6..0000000 --- a/FastRng/MathTools.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; - -namespace FastRng; - -/// -/// Provides some mathematical function, which are not available within in the .NET framework. -/// -public static class MathTools -{ - private static readonly float SQRT_2 = MathF.Sqrt(2.0f); - private static readonly float SQRT_PI = MathF.Sqrt(MathF.PI); - - /// - /// The mathematical gamma function. - /// - /// The value for which you want calculate gamma. - public static float Gamma(float z) - { - // Source: http://rosettacode.org/wiki/Gamma_function#Go - - const float F1 = 6.5f; - const float A1 = .99999999999980993f; - const float A2 = 676.5203681218851f; - const float A3 = 1259.1392167224028f; - const float A4 = 771.32342877765313f; - const float A5 = 176.61502916214059f; - const float A6 = 12.507343278686905f; - const float A7 = .13857109526572012f; - const float A8 = 9.9843695780195716e-6f; - const float A9 = 1.5056327351493116e-7f; - - var t = z + F1; - var x = A1 + - A2 / z - - A3 / (z + 1) + - A4 / (z + 2) - - A5 / (z + 3) + - A6 / (z + 4) - - A7 / (z + 5) + - A8 / (z + 6) + - A9 / (z + 7); - - return SQRT_2 * SQRT_PI * MathF.Pow(t, z - 0.5f) * MathF.Exp(-t) * x; - } - - /// - /// The mathematical factorial function for floating-point numbers. - /// - /// The value, for which you want to know the factorial. - public static float Factorial(float x) => Gamma(x + 1.0f); - - /// - /// The mathematical factorial function for integer numbers. - /// - /// The value, for which you want to know the factorial. - /// Throws, when x is greater than 20. Due to limitations of 64bit ulong type. - public static ulong Factorial(uint x) - { - if (x > 20) - throw new ArgumentOutOfRangeException(nameof(x), $"Cannot compute {x}!, since ulong.max is 18_446_744_073_709_551_615."); - - ulong accumulator = 1; - for (uint factor = 1; factor <= x; factor++) - accumulator *= factor; - - return accumulator; - } - - /// - /// The mathematical factorial function for integer numbers. - /// - /// The value, for which you want to know the factorial. - /// Throws, when x is greater than 20. Due to limitations - /// of 64bit ulong type. Throws also, when x is less than 0. - public static ulong Factorial(int x) - { - if(x < 0) - throw new ArgumentOutOfRangeException(nameof(x), "Given value must be greater as zero."); - - return Factorial((uint) x); - } -} \ No newline at end of file diff --git a/FastRng/MultiThreadedRng.cs b/FastRng/MultiThreadedRng.cs index 2445969..3f27c67 100644 --- a/FastRng/MultiThreadedRng.cs +++ b/FastRng/MultiThreadedRng.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; +using System.Numerics; using System.Threading; using System.Threading.Tasks; @@ -25,7 +26,7 @@ namespace FastRng; /// Please notice: When using the debug environment, MultiThreadedRng uses a smaller buffer size. Please ensure, /// that the production environment uses a release build, though. /// -public sealed class MultiThreadedRng : IRandom, IDisposable +public sealed class MultiThreadedRng : IRandom, IDisposable where TNum : IFloatingPointIeee754, IAdditionOperators { #if DEBUG private const int BUFFER_SIZE = 10_000; @@ -35,6 +36,8 @@ public sealed class MultiThreadedRng : IRandom, IDisposable // The queue size means, how many buffer we store in a queue at the same time: private const int QUEUE_SIZE = 2; + + private static readonly TNum CONST_FLOAT_CONVERSION = TNum.CreateChecked(2.328306435454494e-10f); // Gets used to stop the producer threads: private readonly CancellationTokenSource producerTokenSource = new(); @@ -46,7 +49,7 @@ public sealed class MultiThreadedRng : IRandom, IDisposable private readonly ConcurrentQueue queueIntegers = new(); // The second queue, where to store buffers of uniform random floating point numbers: - private readonly ConcurrentQueue queueFloats = new(); + private readonly ConcurrentQueue queueFloats = new(); // The uint producer thread: private Thread producerRandomUint; @@ -60,7 +63,7 @@ public sealed class MultiThreadedRng : IRandom, IDisposable private uint mZ; // This is the current buffer for the consumer side i.e. the public interfaces: - private float[] currentBuffer = Array.Empty(); + private TNum[] currentBuffer = Array.Empty(); // The current pointer to the next current buffer's address to read from: private int currentBufferPointer = BUFFER_SIZE; @@ -207,11 +210,11 @@ public sealed class MultiThreadedRng : IRandom, IDisposable return; // A local buffer to fill with uniform floats: - var nextBuffer = new float[BUFFER_SIZE]; + var nextBuffer = new TNum[BUFFER_SIZE]; // Generate the necessary number of floats: for (var n = 0; n < nextBuffer.Length && !cancellationToken.IsCancellationRequested; n++) - nextBuffer[n] = (bufferSource[n] + 1.0f) * 2.328306435454494e-10f; + nextBuffer[n] = (TNum.CreateChecked(bufferSource[n]) + TNum.One) * CONST_FLOAT_CONVERSION; // Inside this loop, we try to enqueue the generated buffer: while (!cancellationToken.IsCancellationRequested) @@ -253,7 +256,7 @@ public sealed class MultiThreadedRng : IRandom, IDisposable /// by using multiple threads at the same time. /// /// An optional cancellation token. - public async ValueTask GetUniform(CancellationToken cancel = default) + public async ValueTask GetUniform(CancellationToken cancel = default) { while (!cancel.IsCancellationRequested) { @@ -264,7 +267,7 @@ public sealed class MultiThreadedRng : IRandom, IDisposable var currentBufferReference = this.currentBuffer; // Here, we store the next buffer until we implement it: - var nextBuffer = Array.Empty(); + var nextBuffer = Array.Empty(); // Try to get the next buffer from the queue: while (this.currentBufferPointer >= BUFFER_SIZE && currentBufferReference == this.currentBuffer && !this.queueFloats.TryDequeue(out nextBuffer)) @@ -282,7 +285,7 @@ public sealed class MultiThreadedRng : IRandom, IDisposable // // Case: The consumer cancelled the request. // - return float.NaN; + return TNum.NaN; } } @@ -340,7 +343,7 @@ public sealed class MultiThreadedRng : IRandom, IDisposable // // Case: The consumer cancelled the request. // - return float.NaN; + return TNum.NaN; } private void StopProducer() => this.producerTokenSource.Cancel(); diff --git a/FastRng/ShapeFitter.cs b/FastRng/ShapeFitter.cs index 07b8397..bdb51c8 100644 --- a/FastRng/ShapeFitter.cs +++ b/FastRng/ShapeFitter.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using System.Threading; using System.Threading.Tasks; using FastRng.Distributions; @@ -8,13 +9,13 @@ namespace FastRng; /// /// ShapeFitter is a rejection sampler, cf. https://en.wikipedia.org/wiki/Rejection_sampling /// -public sealed class ShapeFitter +public sealed class ShapeFitter where TNum : IFloatingPointIeee754, IDivisionOperators { - private readonly float[] probabilities; - private readonly IRandom rng; - private readonly float max; - private readonly float sampleSize; - private readonly IDistribution uniform; + private readonly TNum[] probabilities; + private readonly IRandom rng; + private readonly TNum max; + private readonly TNum sampleSize; + private readonly IDistribution uniform; /// /// Creates a shape fitter instance. @@ -22,16 +23,16 @@ public sealed class ShapeFitter /// The function which describes the desired shape. /// The random number generator instance to use. /// The number of sampling steps to sample the given function. - public ShapeFitter(Func shapeFunction, IRandom rng, ushort sampleSize = 50) + public ShapeFitter(Func shapeFunction, IRandom rng, ushort sampleSize = 50) { this.rng = rng; - this.uniform = new Uniform(rng); - this.sampleSize = sampleSize; - this.probabilities = new float[sampleSize]; + this.uniform = new Uniform(rng); + this.sampleSize = TNum.CreateChecked(sampleSize); + this.probabilities = new TNum[sampleSize]; - var sampleStepSize = 1.0f / sampleSize; - var nextStep = 0.0f + sampleStepSize; - var maxValue = 0.0f; + var sampleStepSize = TNum.One / TNum.CreateChecked(sampleSize); + var nextStep = TNum.Zero + sampleStepSize; + var maxValue = TNum.Zero; for (var n = 0; n < sampleSize; n++) { this.probabilities[n] = shapeFunction(nextStep); @@ -49,21 +50,21 @@ public sealed class ShapeFitter /// /// An optional cancellation token. /// The next value regarding the given shape. - public async ValueTask NextNumber(CancellationToken token = default) + public async ValueTask NextNumber(CancellationToken token = default) { while (!token.IsCancellationRequested) { var x = await this.rng.GetUniform(token); - if (float.IsNaN(x)) + if (TNum.IsNaN(x)) return x; - var nextBucket = (int)MathF.Floor(x * this.sampleSize); + var nextBucket = int.CreateChecked(TNum.Floor(x * this.sampleSize)); if (nextBucket >= this.probabilities.Length) nextBucket = this.probabilities.Length - 1; var threshold = this.probabilities[nextBucket]; - var y = await this.uniform.NextNumber(0.0f, this.max, token); - if (float.IsNaN(y)) + var y = await this.uniform.NextNumber(TNum.Zero, this.max, token); + if (TNum.IsNaN(y)) return y; if(y > threshold) @@ -72,6 +73,6 @@ public sealed class ShapeFitter return x; } - return float.NaN; + return TNum.NaN; } } \ No newline at end of file diff --git a/FastRngTests/DecisionTester.cs b/FastRngTests/DecisionTester.cs index bc52009..d48b416 100644 --- a/FastRngTests/DecisionTester.cs +++ b/FastRngTests/DecisionTester.cs @@ -2,9 +2,9 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; using FastRng; +using FastRng.Distributions; +using FastRngTests.Distributions; using NUnit.Framework; -using Uniform = FastRng.Distributions.Uniform; -using WeibullK05La1 = FastRng.Distributions.WeibullK05La1; namespace FastRngTests; @@ -16,8 +16,8 @@ public class DecisionTester [Category(TestCategories.NORMAL)] public async Task DecisionUniform01() { - using var rng = new MultiThreadedRng(); - var dist = new Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new Uniform(rng); var neededCoinTossesA = 0; var neededCoinTossesB = 0; @@ -40,8 +40,8 @@ public class DecisionTester [Category(TestCategories.NORMAL)] public async Task DecisionWeibull01() { - using var rng = new MultiThreadedRng(); - var dist = new WeibullK05La1(rng); + using var rng = new MultiThreadedRng(); + var dist = new WeibullK05La1(rng); var neededCoinTossesA = 0; var neededCoinTossesB = 0; diff --git a/FastRngTests/Distributions/BetaA2B2.cs b/FastRngTests/Distributions/BetaA2B2.cs index 192f395..24887b8 100644 --- a/FastRngTests/Distributions/BetaA2B2.cs +++ b/FastRngTests/Distributions/BetaA2B2.cs @@ -15,8 +15,8 @@ public class BetaA2B2 [Category(TestCategories.NORMAL)] public async Task TestBetaDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.BetaA2B2(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.BetaA2B2(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,9 +48,9 @@ public class BetaA2B2 [Category(TestCategories.NORMAL)] public async Task TestBetaGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.BetaA2B2(rng); + var dist = new FastRng.Distributions.BetaA2B2(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,9 +63,9 @@ public class BetaA2B2 [Category(TestCategories.NORMAL)] public async Task TestBetaGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.BetaA2B2(rng); + var dist = new FastRng.Distributions.BetaA2B2(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class BetaA2B2 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.BetaA2B2(null)); + Assert.Throws(() => new FastRng.Distributions.BetaA2B2(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/BetaA2B5.cs b/FastRngTests/Distributions/BetaA2B5.cs index 3ad4867..5710d58 100644 --- a/FastRngTests/Distributions/BetaA2B5.cs +++ b/FastRngTests/Distributions/BetaA2B5.cs @@ -15,8 +15,8 @@ public class BetaA2B5 [Category(TestCategories.NORMAL)] public async Task TestBetaDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.BetaA2B5(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.BetaA2B5(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,9 +48,9 @@ public class BetaA2B5 [Category(TestCategories.NORMAL)] public async Task TestBetaGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.BetaA2B5(rng); + var dist = new FastRng.Distributions.BetaA2B5(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,9 +63,9 @@ public class BetaA2B5 [Category(TestCategories.NORMAL)] public async Task TestBetaGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.BetaA2B5(rng); + var dist = new FastRng.Distributions.BetaA2B5(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class BetaA2B5 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.BetaA2B5(null)); + Assert.Throws(() => new FastRng.Distributions.BetaA2B5(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/BetaA5B2.cs b/FastRngTests/Distributions/BetaA5B2.cs index ac04112..b7ed5cf 100644 --- a/FastRngTests/Distributions/BetaA5B2.cs +++ b/FastRngTests/Distributions/BetaA5B2.cs @@ -15,8 +15,8 @@ public class BetaA5B2 [Category(TestCategories.NORMAL)] public async Task TestBetaDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.BetaA5B2(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.BetaA5B2(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,9 +48,9 @@ public class BetaA5B2 [Category(TestCategories.NORMAL)] public async Task TestBetaGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.BetaA5B2(rng); + var dist = new FastRng.Distributions.BetaA5B2(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,9 +63,9 @@ public class BetaA5B2 [Category(TestCategories.NORMAL)] public async Task TestBetaGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.BetaA5B2(rng); + var dist = new FastRng.Distributions.BetaA5B2(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class BetaA5B2 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.BetaA5B2(null)); + Assert.Throws(() => new FastRng.Distributions.BetaA5B2(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/CauchyLorentzX0.cs b/FastRngTests/Distributions/CauchyLorentzX0.cs index 84458b3..1555c79 100644 --- a/FastRngTests/Distributions/CauchyLorentzX0.cs +++ b/FastRngTests/Distributions/CauchyLorentzX0.cs @@ -18,8 +18,8 @@ public class CauchyLorentzX0 // The properties of the cauchy distribution cannot be tested by mean, media or variance, // cf. https://en.wikipedia.org/wiki/Cauchy_distribution#Explanation_of_undefined_moments - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.CauchyLorentzX0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.CauchyLorentzX0(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -51,8 +51,8 @@ public class CauchyLorentzX0 [Category(TestCategories.NORMAL)] public async Task TestCauchyGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.CauchyLorentzX0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.CauchyLorentzX0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -66,8 +66,8 @@ public class CauchyLorentzX0 [Category(TestCategories.NORMAL)] public async Task TestCauchyGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.CauchyLorentzX0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.CauchyLorentzX0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -81,6 +81,6 @@ public class CauchyLorentzX0 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.CauchyLorentzX0(null)); + Assert.Throws(() => new FastRng.Distributions.CauchyLorentzX0(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/CauchyLorentzX1.cs b/FastRngTests/Distributions/CauchyLorentzX1.cs index 9b1a7d4..68dcb6c 100644 --- a/FastRngTests/Distributions/CauchyLorentzX1.cs +++ b/FastRngTests/Distributions/CauchyLorentzX1.cs @@ -18,8 +18,8 @@ public class CauchyLorentzX1 // The properties of the cauchy distribution cannot be tested by mean, media or variance, // cf. https://en.wikipedia.org/wiki/Cauchy_distribution#Explanation_of_undefined_moments - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.CauchyLorentzX1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.CauchyLorentzX1(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -51,8 +51,8 @@ public class CauchyLorentzX1 [Category(TestCategories.NORMAL)] public async Task TestCauchyGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.CauchyLorentzX0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.CauchyLorentzX0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -66,8 +66,8 @@ public class CauchyLorentzX1 [Category(TestCategories.NORMAL)] public async Task TestCauchyGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.CauchyLorentzX0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.CauchyLorentzX0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -81,6 +81,6 @@ public class CauchyLorentzX1 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.CauchyLorentzX1(null)); + Assert.Throws(() => new FastRng.Distributions.CauchyLorentzX1(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/ChiSquareK1.cs b/FastRngTests/Distributions/ChiSquareK1.cs index 4d41f52..52cc2a6 100644 --- a/FastRngTests/Distributions/ChiSquareK1.cs +++ b/FastRngTests/Distributions/ChiSquareK1.cs @@ -15,8 +15,8 @@ public class ChiSquareK1 [Category(TestCategories.NORMAL)] public async Task TestChiSquareDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK1(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -51,8 +51,8 @@ public class ChiSquareK1 [Category(TestCategories.NORMAL)] public async Task TestChiSquareGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK1(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -66,8 +66,8 @@ public class ChiSquareK1 [Category(TestCategories.NORMAL)] public async Task TestChiSquareGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK1(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -81,6 +81,6 @@ public class ChiSquareK1 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.ChiSquareK1(null)); + Assert.Throws(() => new FastRng.Distributions.ChiSquareK1(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/ChiSquareK10.cs b/FastRngTests/Distributions/ChiSquareK10.cs index 9bd92b7..3b97cc1 100644 --- a/FastRngTests/Distributions/ChiSquareK10.cs +++ b/FastRngTests/Distributions/ChiSquareK10.cs @@ -15,8 +15,8 @@ public class ChiSquareK10 [Category(TestCategories.NORMAL)] public async Task TestChiSquareDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK10(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -51,8 +51,8 @@ public class ChiSquareK10 [Category(TestCategories.NORMAL)] public async Task TestChiSquareGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK10(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -66,8 +66,8 @@ public class ChiSquareK10 [Category(TestCategories.NORMAL)] public async Task TestChiSquareGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK10(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -81,6 +81,6 @@ public class ChiSquareK10 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.ChiSquareK10(null)); + Assert.Throws(() => new FastRng.Distributions.ChiSquareK10(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/ChiSquareK4.cs b/FastRngTests/Distributions/ChiSquareK4.cs index 38efd0c..9481227 100644 --- a/FastRngTests/Distributions/ChiSquareK4.cs +++ b/FastRngTests/Distributions/ChiSquareK4.cs @@ -15,8 +15,8 @@ public class ChiSquareK4 [Category(TestCategories.NORMAL)] public async Task TestChiSquareDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK4(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK4(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class ChiSquareK4 [Category(TestCategories.NORMAL)] public async Task TestChiSquareGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK4(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK4(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class ChiSquareK4 [Category(TestCategories.NORMAL)] public async Task TestChiSquareGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ChiSquareK4(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ChiSquareK4(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class ChiSquareK4 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.ChiSquareK4(null)); + Assert.Throws(() => new FastRng.Distributions.ChiSquareK4(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/ExponentialLa10.cs b/FastRngTests/Distributions/ExponentialLa10.cs index 51cf379..7cd47fa 100644 --- a/FastRngTests/Distributions/ExponentialLa10.cs +++ b/FastRngTests/Distributions/ExponentialLa10.cs @@ -15,8 +15,8 @@ public class ExponentialLa10 [Category(TestCategories.NORMAL)] public async Task TestExponentialDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ExponentialLa10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ExponentialLa10(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class ExponentialLa10 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ExponentialLa10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ExponentialLa10(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class ExponentialLa10 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ExponentialLa10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ExponentialLa10(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class ExponentialLa10 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.ExponentialLa10(null)); + Assert.Throws(() => new FastRng.Distributions.ExponentialLa10(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/ExponentialLa5.cs b/FastRngTests/Distributions/ExponentialLa5.cs index 66eb16a..05ebd02 100644 --- a/FastRngTests/Distributions/ExponentialLa5.cs +++ b/FastRngTests/Distributions/ExponentialLa5.cs @@ -15,8 +15,8 @@ public class ExponentialLa5 [Category(TestCategories.NORMAL)] public async Task TestExponentialDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ExponentialLa5(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ExponentialLa5(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class ExponentialLa5 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ExponentialLa5(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ExponentialLa5(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class ExponentialLa5 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.ExponentialLa5(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.ExponentialLa5(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class ExponentialLa5 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.ExponentialLa5(null)); + Assert.Throws(() => new FastRng.Distributions.ExponentialLa5(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/GammaA5B15.cs b/FastRngTests/Distributions/GammaA5B15.cs index 24ceb0b..56c04c9 100644 --- a/FastRngTests/Distributions/GammaA5B15.cs +++ b/FastRngTests/Distributions/GammaA5B15.cs @@ -15,8 +15,8 @@ public class GammaA5B15 [Category(TestCategories.NORMAL)] public async Task TestGammaDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.GammaA5B15(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.GammaA5B15(rng); var fra = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class GammaA5B15 [Category(TestCategories.NORMAL)] public async Task TestGammaGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.GammaA5B15(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.GammaA5B15(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class GammaA5B15 [Category(TestCategories.NORMAL)] public async Task TestGammaGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.GammaA5B15(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.GammaA5B15(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class GammaA5B15 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.GammaA5B15(null)); + Assert.Throws(() => new FastRng.Distributions.GammaA5B15(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/InverseExponentialLa10.cs b/FastRngTests/Distributions/InverseExponentialLa10.cs index de7271d..aeed203 100644 --- a/FastRngTests/Distributions/InverseExponentialLa10.cs +++ b/FastRngTests/Distributions/InverseExponentialLa10.cs @@ -15,8 +15,8 @@ public class InverseExponentialLa10 [Category(TestCategories.NORMAL)] public async Task TestExponentialDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseExponentialLa10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseExponentialLa10(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class InverseExponentialLa10 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseExponentialLa10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseExponentialLa10(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class InverseExponentialLa10 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseExponentialLa10(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseExponentialLa10(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class InverseExponentialLa10 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.InverseExponentialLa10(null)); + Assert.Throws(() => new FastRng.Distributions.InverseExponentialLa10(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/InverseExponentialLa5.cs b/FastRngTests/Distributions/InverseExponentialLa5.cs index 1fd872a..1987d3d 100644 --- a/FastRngTests/Distributions/InverseExponentialLa5.cs +++ b/FastRngTests/Distributions/InverseExponentialLa5.cs @@ -15,8 +15,8 @@ public class InverseExponentialLa5 [Category(TestCategories.NORMAL)] public async Task TestExponentialDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseExponentialLa5(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseExponentialLa5(rng); var fqa = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class InverseExponentialLa5 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseExponentialLa5(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseExponentialLa5(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class InverseExponentialLa5 [Category(TestCategories.NORMAL)] public async Task TestExponentialGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseExponentialLa5(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseExponentialLa5(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class InverseExponentialLa5 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.InverseExponentialLa5(null)); + Assert.Throws(() => new FastRng.Distributions.InverseExponentialLa5(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/InverseGammaA3B05.cs b/FastRngTests/Distributions/InverseGammaA3B05.cs index 9027f7f..5ff6244 100644 --- a/FastRngTests/Distributions/InverseGammaA3B05.cs +++ b/FastRngTests/Distributions/InverseGammaA3B05.cs @@ -15,8 +15,8 @@ public class InverseGammaA3B05 [Category(TestCategories.NORMAL)] public async Task TestInverseGammaDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseGammaA3B05(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseGammaA3B05(rng); var fra = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class InverseGammaA3B05 [Category(TestCategories.NORMAL)] public async Task TestInverseGammaGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseGammaA3B05(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseGammaA3B05(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class InverseGammaA3B05 [Category(TestCategories.NORMAL)] public async Task TestInverseGammaGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.InverseGammaA3B05(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.InverseGammaA3B05(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class InverseGammaA3B05 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.InverseGammaA3B05(null)); + Assert.Throws(() => new FastRng.Distributions.InverseGammaA3B05(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/LaplaceB01M0.cs b/FastRngTests/Distributions/LaplaceB01M0.cs index f24132b..3f3f6d5 100644 --- a/FastRngTests/Distributions/LaplaceB01M0.cs +++ b/FastRngTests/Distributions/LaplaceB01M0.cs @@ -15,8 +15,8 @@ public class LaplaceB01M0 [Category(TestCategories.NORMAL)] public async Task TestLaplaceDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LaplaceB01M0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LaplaceB01M0(rng); var fra = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class LaplaceB01M0 [Category(TestCategories.NORMAL)] public async Task TestLaplaceGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LaplaceB01M0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LaplaceB01M0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class LaplaceB01M0 [Category(TestCategories.NORMAL)] public async Task TestLaplaceGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LaplaceB01M0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LaplaceB01M0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class LaplaceB01M0 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.LaplaceB01M0(null)); + Assert.Throws(() => new FastRng.Distributions.LaplaceB01M0(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/LaplaceB01M05.cs b/FastRngTests/Distributions/LaplaceB01M05.cs index 5cae3bd..d287262 100644 --- a/FastRngTests/Distributions/LaplaceB01M05.cs +++ b/FastRngTests/Distributions/LaplaceB01M05.cs @@ -15,8 +15,8 @@ public class LaplaceB01M05 [Category(TestCategories.NORMAL)] public async Task TestLaplaceDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LaplaceB01M05(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LaplaceB01M05(rng); var fra = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class LaplaceB01M05 [Category(TestCategories.NORMAL)] public async Task TestLaplaceGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LaplaceB01M05(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LaplaceB01M05(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class LaplaceB01M05 [Category(TestCategories.NORMAL)] public async Task TestLaplaceGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LaplaceB01M05(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LaplaceB01M05(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class LaplaceB01M05 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.LaplaceB01M05(null)); + Assert.Throws(() => new FastRng.Distributions.LaplaceB01M05(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/LogNormalS1M0.cs b/FastRngTests/Distributions/LogNormalS1M0.cs index 4b6ad45..86e88d8 100644 --- a/FastRngTests/Distributions/LogNormalS1M0.cs +++ b/FastRngTests/Distributions/LogNormalS1M0.cs @@ -15,8 +15,8 @@ public class LogNormalS1M0 [Category(TestCategories.NORMAL)] public async Task TestLogNormalDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LogNormalS1M0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LogNormalS1M0(rng); var fra = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class LogNormalS1M0 [Category(TestCategories.NORMAL)] public async Task TestLogNormalGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LogNormalS1M0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LogNormalS1M0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class LogNormalS1M0 [Category(TestCategories.NORMAL)] public async Task TestLogNormalGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.LogNormalS1M0(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.LogNormalS1M0(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class LogNormalS1M0 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.LogNormalS1M0(null)); + Assert.Throws(() => new FastRng.Distributions.LogNormalS1M0(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/NormalS02M05.cs b/FastRngTests/Distributions/NormalS02M05.cs index 4bc88ed..faf2d71 100644 --- a/FastRngTests/Distributions/NormalS02M05.cs +++ b/FastRngTests/Distributions/NormalS02M05.cs @@ -18,8 +18,8 @@ public class NormalS02M05 const float MEAN = 0.5f; const float STANDARD_DEVIATION = 0.2f; - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.NormalS02M05(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.NormalS02M05(rng); var stats = new RunningStatistics(); var fra = new FrequencyAnalysis(); @@ -44,9 +44,9 @@ public class NormalS02M05 [Category(TestCategories.NORMAL)] public async Task TestNormalGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.NormalS02M05(rng); + var dist = new FastRng.Distributions.NormalS02M05(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -59,9 +59,9 @@ public class NormalS02M05 [Category(TestCategories.NORMAL)] public async Task TestNormalGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.NormalS02M05(rng); + var dist = new FastRng.Distributions.NormalS02M05(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -74,6 +74,6 @@ public class NormalS02M05 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.NormalS02M05(null)); + Assert.Throws(() => new FastRng.Distributions.NormalS02M05(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/StudentTNu1.cs b/FastRngTests/Distributions/StudentTNu1.cs index fcec86a..219cf31 100644 --- a/FastRngTests/Distributions/StudentTNu1.cs +++ b/FastRngTests/Distributions/StudentTNu1.cs @@ -15,8 +15,8 @@ public class StudentTNu1 [Category(TestCategories.NORMAL)] public async Task TestStudentTDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.StudentTNu1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.StudentTNu1(rng); var fra = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class StudentTNu1 [Category(TestCategories.NORMAL)] public async Task TestStudentTGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.StudentTNu1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.StudentTNu1(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class StudentTNu1 [Category(TestCategories.NORMAL)] public async Task TestStudentTGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.StudentTNu1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.StudentTNu1(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class StudentTNu1 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.StudentTNu1(null)); + Assert.Throws(() => new FastRng.Distributions.StudentTNu1(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/Uniform.cs b/FastRngTests/Distributions/Uniform.cs index ca15280..913229a 100644 --- a/FastRngTests/Distributions/Uniform.cs +++ b/FastRngTests/Distributions/Uniform.cs @@ -20,7 +20,7 @@ public class Uniform const float MEAN = 0.5f * (A + B); const float VARIANCE = (1.0f / 12.0f) * (B - A) * (B - A); - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var stats = new RunningStatistics(); var fra = new FrequencyAnalysis(); @@ -58,7 +58,7 @@ public class Uniform const float P_HIGH = 1.0f - 0.25f * FAILURE_PROBABILITY; var samples = new float[NUM_ROUNDS]; - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); int n; for (n = 0; n != NUM_ROUNDS; ++n) @@ -115,9 +115,9 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestUniformGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.Uniform(rng); + var dist = new FastRng.Distributions.Uniform(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -130,9 +130,9 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestUniformGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; - var dist = new FastRng.Distributions.Uniform(rng); + var dist = new FastRng.Distributions.Uniform(rng); for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -145,7 +145,7 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestUniformGeneratorWithRange04() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await rng.GetUniform(); @@ -159,8 +159,8 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestRange05Uint() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 1_000_000; for (var n = 0; n < runs; n++) @@ -175,8 +175,8 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestRange05Ulong() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 1_000_000; for (var n = 0; n < runs; n++) @@ -191,8 +191,8 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestRange05Float() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 1_000_000; for (var n = 0; n < runs; n++) @@ -206,8 +206,8 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestDistribution001Uint() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 1_000_000; for (var n = 0; n < runs; n++) @@ -220,8 +220,8 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestDistribution001Ulong() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 1_000_000; for (var n = 0; n < runs; n++) @@ -234,8 +234,8 @@ public class Uniform [Category(TestCategories.NORMAL)] public async Task TestDistribution001Float() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 1_000_000; for (var n = 0; n < runs; n++) @@ -248,8 +248,8 @@ public class Uniform [Category(TestCategories.LONG_RUNNING)] public async Task TestDistribution002Uint() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 100_000_000; for (var n = 0; n < runs; n++) @@ -262,8 +262,8 @@ public class Uniform [Category(TestCategories.LONG_RUNNING)] public async Task TestDistribution002Ulong() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 100_000_000; for (var n = 0; n < runs; n++) @@ -276,8 +276,8 @@ public class Uniform [Category(TestCategories.LONG_RUNNING)] public async Task TestDistribution002Float() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.Uniform(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.Uniform(rng); var distribution = new uint[101]; var runs = 100_000_000; for (var n = 0; n < runs; n++) @@ -291,6 +291,6 @@ public class Uniform [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.Uniform(null)); + Assert.Throws(() => new FastRng.Distributions.Uniform(null)); } } \ No newline at end of file diff --git a/FastRngTests/Distributions/WeibullK05La1.cs b/FastRngTests/Distributions/WeibullK05La1.cs index 89fa45c..456276d 100644 --- a/FastRngTests/Distributions/WeibullK05La1.cs +++ b/FastRngTests/Distributions/WeibullK05La1.cs @@ -15,8 +15,8 @@ public class WeibullK05La1 [Category(TestCategories.NORMAL)] public async Task TestWeibullDistribution01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.WeibullK05La1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.WeibullK05La1(rng); var fra = new FrequencyAnalysis(); for (var n = 0; n < 100_000; n++) @@ -48,8 +48,8 @@ public class WeibullK05La1 [Category(TestCategories.NORMAL)] public async Task TestWeibullGeneratorWithRange01() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.WeibullK05La1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.WeibullK05La1(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(-1.0f, 1.0f); @@ -63,8 +63,8 @@ public class WeibullK05La1 [Category(TestCategories.NORMAL)] public async Task TestWeibullGeneratorWithRange02() { - using var rng = new MultiThreadedRng(); - var dist = new FastRng.Distributions.WeibullK05La1(rng); + using var rng = new MultiThreadedRng(); + var dist = new FastRng.Distributions.WeibullK05La1(rng); var samples = new float[1_000]; for (var n = 0; n < samples.Length; n++) samples[n] = await dist.NextNumber(0.0f, 1.0f); @@ -78,6 +78,6 @@ public class WeibullK05La1 [Category(TestCategories.NORMAL)] public void NoRandomNumberGenerator01() { - Assert.Throws(() => new FastRng.Distributions.WeibullK05La1(null)); + Assert.Throws(() => new FastRng.Distributions.WeibullK05La1(null)); } } \ No newline at end of file diff --git a/FastRngTests/MathToolsTests.cs b/FastRngTests/MathToolsTests.cs index 46d297e..a866df1 100644 --- a/FastRngTests/MathToolsTests.cs +++ b/FastRngTests/MathToolsTests.cs @@ -15,7 +15,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest01() { - Assert.That(MathTools.Gamma(-0.5f), Is.EqualTo(-3.544907701811087f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(-0.5f), Is.EqualTo(-3.544907701811087f).Within(1e-6f)); } [Test] @@ -23,7 +23,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest02() { - Assert.That(MathTools.Gamma(0.1f), Is.EqualTo(9.51350975f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(0.1f), Is.EqualTo(9.51350975f).Within(1e-6f)); } [Test] @@ -31,7 +31,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest03() { - Assert.That(MathTools.Gamma(0.5f), Is.EqualTo(1.772453850905517f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(0.5f), Is.EqualTo(1.772453850905517f).Within(1e-6f)); } [Test] @@ -39,7 +39,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest04() { - Assert.That(MathTools.Gamma(1.0f), Is.EqualTo(1.0f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(1.0f), Is.EqualTo(1.0f).Within(1e-6f)); } [Test] @@ -47,7 +47,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest05() { - Assert.That(MathTools.Gamma(1.5f), Is.EqualTo(0.8862269254527587f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(1.5f), Is.EqualTo(0.8862269254527587f).Within(1e-6f)); } [Test] @@ -55,7 +55,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest06() { - Assert.That(MathTools.Gamma(2.0f), Is.EqualTo(1.0f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(2.0f), Is.EqualTo(1.0f).Within(1e-6f)); } [Test] @@ -63,7 +63,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest07() { - Assert.That(MathTools.Gamma(3.0f), Is.EqualTo(2.0f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(3.0f), Is.EqualTo(2.0f).Within(1e-6f)); } [Test] @@ -71,7 +71,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest08() { - Assert.That(MathTools.Gamma(10.0f), Is.EqualTo(362_880.719f).Within(1e-6f)); + Assert.That(FloatingPointMathTools.Gamma(10.0f), Is.EqualTo(362_880.719f).Within(1e-6f)); } [Test] @@ -79,7 +79,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest09() { - Assert.That(MathTools.Gamma(140.0f), Is.EqualTo(float.NaN)); + Assert.That(FloatingPointMathTools.Gamma(140.0f), Is.EqualTo(float.NaN)); } [Test] @@ -87,7 +87,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void GammaTest10() { - Assert.That(MathTools.Gamma(170.0f), Is.EqualTo(float.NaN)); + Assert.That(FloatingPointMathTools.Gamma(170.0f), Is.EqualTo(float.NaN)); } #endregion @@ -99,7 +99,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger01() { - Assert.That(MathTools.Factorial(0), Is.EqualTo(1)); + Assert.That(IntegerMathTools.Factorial(0), Is.EqualTo(1)); } [Test] @@ -107,7 +107,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger02() { - Assert.That(MathTools.Factorial(1), Is.EqualTo(1)); + Assert.That(IntegerMathTools.Factorial(1), Is.EqualTo(1)); } [Test] @@ -115,7 +115,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger03() { - Assert.That(MathTools.Factorial(2), Is.EqualTo(2)); + Assert.That(IntegerMathTools.Factorial(2), Is.EqualTo(2)); } [Test] @@ -123,7 +123,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger04() { - Assert.That(MathTools.Factorial(3), Is.EqualTo(6)); + Assert.That(IntegerMathTools.Factorial(3), Is.EqualTo(6)); } [Test] @@ -131,7 +131,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger05() { - Assert.That(MathTools.Factorial(4), Is.EqualTo(24)); + Assert.That(IntegerMathTools.Factorial(4), Is.EqualTo(24)); } [Test] @@ -139,7 +139,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger06() { - Assert.That(MathTools.Factorial(5), Is.EqualTo(120)); + Assert.That(IntegerMathTools.Factorial(5), Is.EqualTo(120)); } [Test] @@ -147,7 +147,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger07() { - Assert.That(MathTools.Factorial(6), Is.EqualTo(720)); + Assert.That(IntegerMathTools.Factorial(6), Is.EqualTo(720)); } [Test] @@ -155,7 +155,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger08() { - Assert.That(MathTools.Factorial(7), Is.EqualTo(5_040)); + Assert.That(IntegerMathTools.Factorial(7), Is.EqualTo(5_040)); } [Test] @@ -163,7 +163,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger09() { - Assert.That(MathTools.Factorial(8), Is.EqualTo(40_320)); + Assert.That(IntegerMathTools.Factorial(8), Is.EqualTo(40_320)); } [Test] @@ -171,7 +171,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger10() { - Assert.That(MathTools.Factorial(9), Is.EqualTo(362_880)); + Assert.That(IntegerMathTools.Factorial(9), Is.EqualTo(362_880)); } [Test] @@ -179,7 +179,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger11() { - Assert.That(MathTools.Factorial(10), Is.EqualTo(3_628_800)); + Assert.That(IntegerMathTools.Factorial(10), Is.EqualTo(3_628_800)); } [Test] @@ -187,7 +187,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger12() { - Assert.That(MathTools.Factorial(11), Is.EqualTo(39_916_800)); + Assert.That(IntegerMathTools.Factorial(11), Is.EqualTo(39_916_800)); } [Test] @@ -195,7 +195,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger13() { - Assert.That(MathTools.Factorial(12), Is.EqualTo(479_001_600)); + Assert.That(IntegerMathTools.Factorial(12), Is.EqualTo(479_001_600)); } [Test] @@ -203,7 +203,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger14() { - Assert.That(MathTools.Factorial(13), Is.EqualTo(6_227_020_800)); + Assert.That(IntegerMathTools.Factorial(13), Is.EqualTo(6_227_020_800)); } [Test] @@ -211,7 +211,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger15() { - Assert.That(MathTools.Factorial(14), Is.EqualTo(87_178_291_200)); + Assert.That(IntegerMathTools.Factorial(14), Is.EqualTo(87_178_291_200)); } [Test] @@ -219,7 +219,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger16() { - Assert.That(MathTools.Factorial(15), Is.EqualTo(1_307_674_368_000)); + Assert.That(IntegerMathTools.Factorial(15), Is.EqualTo(1_307_674_368_000)); } [Test] @@ -227,7 +227,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger17() { - Assert.That(MathTools.Factorial(16), Is.EqualTo(20_922_789_888_000)); + Assert.That(IntegerMathTools.Factorial(16), Is.EqualTo(20_922_789_888_000)); } [Test] @@ -235,7 +235,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger18() { - Assert.That(MathTools.Factorial(17), Is.EqualTo(355_687_428_096_000)); + Assert.That(IntegerMathTools.Factorial(17), Is.EqualTo(355_687_428_096_000)); } [Test] @@ -243,7 +243,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger19() { - Assert.That(MathTools.Factorial(18), Is.EqualTo(6_402_373_705_728_000)); + Assert.That(IntegerMathTools.Factorial(18), Is.EqualTo(6_402_373_705_728_000)); } [Test] @@ -251,7 +251,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger20() { - Assert.That(MathTools.Factorial(19), Is.EqualTo(121_645_100_408_832_000)); + Assert.That(IntegerMathTools.Factorial(19), Is.EqualTo(121_645_100_408_832_000)); } [Test] @@ -259,7 +259,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger21() { - Assert.That(MathTools.Factorial(20), Is.EqualTo(2_432_902_008_176_640_000)); + Assert.That(IntegerMathTools.Factorial(20), Is.EqualTo(2_432_902_008_176_640_000)); } [Test] @@ -267,7 +267,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger22() { - Assert.Throws(() => MathTools.Factorial(21)); + Assert.Throws(() => IntegerMathTools.Factorial(21)); // Note: 21! is not possible in C# until we got 128 bit integers, since: // ulong.max == 18_446_744_073_709_551_615 < 51_090_942_171_709_400_000 @@ -278,27 +278,11 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialInteger23() { - Assert.Throws(() => MathTools.Factorial(45_646)); + Assert.Throws(() => IntegerMathTools.Factorial(45_646)); // Note: 45_646! is not possible in C# since: // ulong.max == 18_446_744_073_709_551_615 } - - [Test] - [Category(TestCategories.COVER)] - [Category(TestCategories.NORMAL)] - public void FactorialInteger24() - { - Assert.Throws(() => MathTools.Factorial(-1)); - } - - [Test] - [Category(TestCategories.COVER)] - [Category(TestCategories.NORMAL)] - public void FactorialInteger25() - { - Assert.Throws(() => MathTools.Factorial(-6_565)); - } #endregion @@ -309,7 +293,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint01() { - Assert.That(MathTools.Factorial(0.5f), Is.EqualTo(0.886226925f).Within(1e6f)); + Assert.That(FloatingPointMathTools.Factorial(0.5f), Is.EqualTo(0.886226925f).Within(1e6f)); } [Test] @@ -317,7 +301,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint02() { - Assert.That(MathTools.Factorial(1.5f), Is.EqualTo(1.329340388f).Within(1e6f)); + Assert.That(FloatingPointMathTools.Factorial(1.5f), Is.EqualTo(1.329340388f).Within(1e6f)); } [Test] @@ -325,7 +309,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint03() { - Assert.That(MathTools.Factorial(-1.5f), Is.EqualTo(-1.329340388f).Within(1e6f)); + Assert.That(FloatingPointMathTools.Factorial(-1.5f), Is.EqualTo(-1.329340388f).Within(1e6f)); } [Test] @@ -333,7 +317,7 @@ public class MathToolsTests [Category(TestCategories.NORMAL)] public void FactorialFloatingPoint04() { - Assert.That(MathTools.Factorial(7.5f), Is.EqualTo(14_034.407293483f).Within(1e6f)); + Assert.That(FloatingPointMathTools.Factorial(7.5f), Is.EqualTo(14_034.407293483f).Within(1e6f)); } #endregion diff --git a/FastRngTests/MultiThreadedRngTests.cs b/FastRngTests/MultiThreadedRngTests.cs index 280aac6..310ff5f 100644 --- a/FastRngTests/MultiThreadedRngTests.cs +++ b/FastRngTests/MultiThreadedRngTests.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using FastRng; using FastRng.Distributions; +using FastRngTests.Distributions; using NUnit.Framework; namespace FastRngTests; @@ -11,14 +12,14 @@ namespace FastRngTests; [ExcludeFromCodeCoverage] public class MultiThreadedRngTests { - private readonly IRandom rng = new MultiThreadedRng(); + private readonly IRandom rng = new MultiThreadedRng(); [Test] [Category(TestCategories.COVER)] [Category(TestCategories.NORMAL)] public async Task TestRange01Uint() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); for (uint n = 0; n < 1_000_000; n++) Assert.That(await dist.NextNumber(n, 100_000 + n), Is.InRange(n, 100_000 + n)); } @@ -28,7 +29,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange01Ulong() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); for (ulong n = 0; n < 1_000_000; n++) Assert.That(await dist.NextNumber(n, 100_000 + n), Is.InRange(n, 100_000 + n)); } @@ -38,7 +39,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange01Float() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); for (var n = 0.0f; n < 1e6f; n++) Assert.That(await dist.NextNumber(n, 100_000 + n), Is.InRange(n, 100_000 + n)); } @@ -48,7 +49,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange02Uint() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); Assert.That(await dist.NextNumber(5, 5), Is.EqualTo(5)); Assert.That(await dist.NextNumber(0, 0), Is.EqualTo(0)); Assert.That(await dist.NextNumber(3_000_000_000, 3_000_000_000), Is.EqualTo(3_000_000_000)); @@ -59,7 +60,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange02Ulong() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); Assert.That(await dist.NextNumber(5UL, 5), Is.EqualTo(5)); Assert.That(await dist.NextNumber(0UL, 0), Is.EqualTo(0)); Assert.That(await dist.NextNumber(3_000_000_000UL, 3_000_000_000), Is.EqualTo(3_000_000_000)); @@ -70,7 +71,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange02Float() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); Assert.That(await dist.NextNumber(5f, 5f), Is.EqualTo(5)); Assert.That(await dist.NextNumber(0f, 0f), Is.EqualTo(0)); Assert.That(await dist.NextNumber(3e9f, 3e9f), Is.EqualTo(3e9f)); @@ -81,7 +82,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange03Uint() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); Assert.That(await dist.NextNumber(5, 6), Is.InRange(5, 6)); Assert.That(await dist.NextNumber(0, 1), Is.InRange(0, 1)); Assert.That(await dist.NextNumber(3_000_000_000, 3_000_000_002), Is.InRange(3_000_000_000, 3_000_000_002)); @@ -92,7 +93,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange03Ulong() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); Assert.That(await dist.NextNumber(5UL, 6), Is.InRange(5, 6)); Assert.That(await dist.NextNumber(0UL, 1), Is.InRange(0, 1)); Assert.That(await dist.NextNumber(3_000_000_000UL, 3_000_000_002), Is.InRange(3_000_000_000, 3_000_000_002)); @@ -103,7 +104,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange03Float() { - var dist = new Uniform(this.rng); + var dist = new Uniform(this.rng); Assert.That(await dist.NextNumber(5f, 6f), Is.InRange(5f, 6f)); Assert.That(await dist.NextNumber(0f, 1f), Is.InRange(0f, 1f)); Assert.That(await dist.NextNumber(3e9f, 3e9f+2f), Is.InRange(3e9f, 3e9f+2f)); @@ -114,8 +115,8 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange04Uint() { - var distUniform = new Uniform(this.rng); - var distNormal = new NormalS02M05(this.rng); + var distUniform = new Uniform(this.rng); + var distNormal = new NormalS02M05(this.rng); Assert.That(await distUniform.NextNumber(10, 1), Is.InRange(1, 10)); Assert.That(await distNormal.NextNumber(10, 1), Is.InRange(1, 10)); @@ -129,8 +130,8 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange04Ulong() { - var distUniform = new Uniform(this.rng); - var distNormal = new NormalS02M05(this.rng); + var distUniform = new Uniform(this.rng); + var distNormal = new NormalS02M05(this.rng); Assert.That(await distUniform.NextNumber(10UL, 1), Is.InRange(1, 10)); Assert.That(await distNormal.NextNumber(10UL, 1), Is.InRange(1, 10)); @@ -144,8 +145,8 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestRange04Float() { - var distUniform = new Uniform(this.rng); - var distNormal = new NormalS02M05(this.rng); + var distUniform = new Uniform(this.rng); + var distNormal = new NormalS02M05(this.rng); Assert.That(await distUniform.NextNumber(10.0f, 1), Is.InRange(1, 10)); Assert.That(await distNormal.NextNumber(10.0f, 1), Is.InRange(1, 10)); @@ -158,8 +159,8 @@ public class MultiThreadedRngTests [Category(TestCategories.LONG_RUNNING)] public async Task TestRange05() { - var distUniform = new Uniform(this.rng); - var distLorentz = new CauchyLorentzX1(this.rng); + var distUniform = new Uniform(this.rng); + var distLorentz = new CauchyLorentzX1(this.rng); var rngContains0 = false; var rngContains1 = false; @@ -229,7 +230,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestStoppingProducers01() { - var rng2 = new MultiThreadedRng(); + var rng2 = new MultiThreadedRng(); rng2.Dispose(); var masterToken = new CancellationTokenSource(TimeSpan.FromSeconds(16)).Token; @@ -255,19 +256,19 @@ public class MultiThreadedRngTests Assert.That(wasCanceled, Is.True, "The consumer was not canceled"); var tokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(3)); - await new NormalS02M05(rng2).NextNumber(tokenSource2.Token); + await new NormalS02M05(rng2).NextNumber(tokenSource2.Token); Assert.That(tokenSource2.IsCancellationRequested, Is.True); tokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(3)); - await new NormalS02M05(rng2).NextNumber(-1f, 1f, tokenSource2.Token); + await new NormalS02M05(rng2).NextNumber(-1f, 1f, tokenSource2.Token); Assert.That(tokenSource2.IsCancellationRequested, Is.True); tokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(3)); - await new NormalS02M05(rng2).NextNumber(0u, 6u, tokenSource2.Token); + await new NormalS02M05(rng2).NextNumber(0u, 6u, tokenSource2.Token); Assert.That(tokenSource2.IsCancellationRequested, Is.True); tokenSource2 = new CancellationTokenSource(TimeSpan.FromSeconds(3)); - await new NormalS02M05(rng2).NextNumber(0ul, 6ul, tokenSource2.Token); + await new NormalS02M05(rng2).NextNumber(0ul, 6ul, tokenSource2.Token); Assert.That(tokenSource2.IsCancellationRequested, Is.True); } @@ -276,9 +277,9 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task OneSeed01() { - using var rng1 = new MultiThreadedRng(6); - using var rng2 = new MultiThreadedRng(6); - using var rng3 = new MultiThreadedRng(7); + using var rng1 = new MultiThreadedRng(6); + using var rng2 = new MultiThreadedRng(6); + using var rng3 = new MultiThreadedRng(7); var rng1Sample = new float[10]; for (var n = 0; n < rng1Sample.Length; n++) @@ -302,10 +303,10 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TwoSeeds01() { - using var rng1 = new MultiThreadedRng(3, 6); - using var rng2 = new MultiThreadedRng(3, 6); - using var rng3 = new MultiThreadedRng(3, 7); - using var rng4 = new MultiThreadedRng(6, 3); + using var rng1 = new MultiThreadedRng(3, 6); + using var rng2 = new MultiThreadedRng(3, 6); + using var rng3 = new MultiThreadedRng(3, 7); + using var rng4 = new MultiThreadedRng(6, 3); var rng1Sample = new float[10]; for (var n = 0; n < rng1Sample.Length; n++) @@ -336,9 +337,9 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task NoSeed01() { - using var rng1 = new MultiThreadedRng(); - using var rng2 = new MultiThreadedRng(); - using var rng3 = new MultiThreadedRng(); + using var rng1 = new MultiThreadedRng(); + using var rng2 = new MultiThreadedRng(); + using var rng3 = new MultiThreadedRng(); var rng1Sample = new float[10]; for (var n = 0; n < rng1Sample.Length; n++) @@ -366,8 +367,8 @@ public class MultiThreadedRngTests var token = tokenSource.Token; tokenSource.Cancel(); - using var rng2 = new MultiThreadedRng(); - var dist = new Uniform(this.rng); + using var rng2 = new MultiThreadedRng(); + var dist = new Uniform(this.rng); Assert.That(await dist.NextNumber(1, 100_000, token), Is.EqualTo(0)); } @@ -380,7 +381,7 @@ public class MultiThreadedRngTests var token = tokenSource.Token; tokenSource.Cancel(); - using var rng2 = new MultiThreadedRng(); + using var rng2 = new MultiThreadedRng(); Assert.That(await rng2.GetUniform(token), Is.NaN); } @@ -389,7 +390,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestDeterministic01() { - using var rng2 = new MultiThreadedRng(16); + using var rng2 = new MultiThreadedRng(16); Assert.That(await rng2.GetUniform(), Is.EqualTo(0.12712699).Within(1e-7f)); Assert.That(await rng2.GetUniform(), Is.EqualTo(0.5764246).Within(1e-7f)); @@ -428,8 +429,8 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestDeterministic02() { - using var rng2 = new MultiThreadedRng(16); - var dist = new Uniform(rng2); + using var rng2 = new MultiThreadedRng(16); + var dist = new Uniform(rng2); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(13)); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(58)); @@ -468,8 +469,8 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestDeterministic03() { - using var rng2 = new MultiThreadedRng(16); - var dist = new CauchyLorentzX0(rng2); + using var rng2 = new MultiThreadedRng(16); + var dist = new CauchyLorentzX0(rng2); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(11)); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(17)); @@ -508,7 +509,7 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestDeterministic01b() { - using var rng2 = new MultiThreadedRng(16, 362_436_069); + using var rng2 = new MultiThreadedRng(16, 362_436_069); Assert.That(await rng2.GetUniform(), Is.EqualTo(0.12712699).Within(1e-7f)); Assert.That(await rng2.GetUniform(), Is.EqualTo(0.5764246).Within(1e-7f)); @@ -547,8 +548,8 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestDeterministic02b() { - using var rng2 = new MultiThreadedRng(16, 362_436_069); - var dist = new Uniform(rng2); + using var rng2 = new MultiThreadedRng(16, 362_436_069); + var dist = new Uniform(rng2); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(13)); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(58)); @@ -587,8 +588,8 @@ public class MultiThreadedRngTests [Category(TestCategories.NORMAL)] public async Task TestDeterministic03b() { - using var rng2 = new MultiThreadedRng(16, 362_436_069); - var dist = new CauchyLorentzX0(rng2); + using var rng2 = new MultiThreadedRng(16, 362_436_069); + var dist = new CauchyLorentzX0(rng2); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(11)); Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(17)); diff --git a/FastRngTests/PerformanceTests.cs b/FastRngTests/PerformanceTests.cs index 6226945..26e7114 100644 --- a/FastRngTests/PerformanceTests.cs +++ b/FastRngTests/PerformanceTests.cs @@ -20,7 +20,7 @@ public class PerformanceTests [Category(TestCategories.PERFORMANCE)] public async Task Generate1MUniform() { - using var rng = new MultiThreadedRng(); + using var rng = new MultiThreadedRng(); var data = new float[1_000_000]; var stopwatch = new Stopwatch(); Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator @@ -38,8 +38,8 @@ public class PerformanceTests [Category(TestCategories.PERFORMANCE)] public async Task Generate1MNormal() { - using var rng = new MultiThreadedRng(); - var dist = new NormalS02M05(rng); + using var rng = new MultiThreadedRng(); + var dist = new NormalS02M05(rng); var data = new float[1_000_000]; var stopwatch = new Stopwatch(); Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator @@ -57,8 +57,8 @@ public class PerformanceTests [Category(TestCategories.PERFORMANCE)] public async Task Generate1MChiSquare() { - using var rng = new MultiThreadedRng(); - var dist = new ChiSquareK4(rng); + using var rng = new MultiThreadedRng(); + var dist = new ChiSquareK4(rng); var data = new float[1_000_000]; var stopwatch = new Stopwatch(); Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator