Applied .NET 7 syntax or feature changes
This commit is contained in:
parent
38764d5d97
commit
e8cf1284d7
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class BetaA2B2 : Distribution
|
public sealed class BetaA2B2 : Distribution
|
||||||
{
|
{
|
||||||
private const float ALPHA = 2f;
|
private const float ALPHA = 2f;
|
||||||
@ -14,4 +14,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class BetaA2B5 : Distribution
|
public sealed class BetaA2B5 : Distribution
|
||||||
{
|
{
|
||||||
private const float ALPHA = 2f;
|
private const float ALPHA = 2f;
|
||||||
@ -14,4 +14,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class BetaA5B2 : Distribution
|
public sealed class BetaA5B2 : Distribution
|
||||||
{
|
{
|
||||||
private const float ALPHA = 5f;
|
private const float ALPHA = 5f;
|
||||||
@ -14,4 +14,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class CauchyLorentzX0 : Distribution
|
public sealed class CauchyLorentzX0 : Distribution
|
||||||
{
|
{
|
||||||
private const float CONSTANT = 0.31f;
|
private const float CONSTANT = 0.31f;
|
||||||
@ -14,4 +14,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
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 float ShapeFunction(float x) => CONSTANT * (1.0f / (MathF.PI * SCALE)) * ((SCALE * SCALE) / (MathF.Pow(x - MEDIAN, 2f) + (SCALE * SCALE)));
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class CauchyLorentzX1 : Distribution
|
public sealed class CauchyLorentzX1 : Distribution
|
||||||
{
|
{
|
||||||
private const float CONSTANT = 0.31f;
|
private const float CONSTANT = 0.31f;
|
||||||
@ -14,4 +14,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
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 float ShapeFunction(float x) => CONSTANT * (1.0f / (MathF.PI * SCALE)) * ((SCALE * SCALE) / (MathF.Pow(x - MEDIAN, 2f) + (SCALE * SCALE)));
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class ChiSquareK1 : Distribution
|
public sealed class ChiSquareK1 : Distribution
|
||||||
{
|
{
|
||||||
private const float K = 1.0f;
|
private const float K = 1.0f;
|
||||||
@ -24,4 +24,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class ChiSquareK10 : Distribution
|
public sealed class ChiSquareK10 : Distribution
|
||||||
{
|
{
|
||||||
private const float K = 10.0f;
|
private const float K = 10.0f;
|
||||||
@ -24,4 +24,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class ChiSquareK4 : Distribution
|
public sealed class ChiSquareK4 : Distribution
|
||||||
{
|
{
|
||||||
private const float K = 4.0f;
|
private const float K = 4.0f;
|
||||||
@ -24,4 +24,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
||||||
}
|
}
|
||||||
}
|
|
@ -2,20 +2,18 @@ using System;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public abstract class Distribution : IDistribution
|
public abstract class Distribution : IDistribution
|
||||||
{
|
{
|
||||||
private readonly ShapeFitter fitter;
|
private readonly ShapeFitter fitter;
|
||||||
private readonly IRandom random;
|
|
||||||
|
|
||||||
protected Distribution(IRandom rng)
|
protected Distribution(IRandom rng)
|
||||||
{
|
{
|
||||||
if (rng == null)
|
if (rng == null)
|
||||||
throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed.");
|
throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed.");
|
||||||
|
|
||||||
this.random = rng;
|
this.fitter = new ShapeFitter(this.ShapeFunction, rng, 100);
|
||||||
this.fitter = new ShapeFitter(this.ShapeFunction, this.random, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private protected abstract float ShapeFunction(float x);
|
private protected abstract float ShapeFunction(float x);
|
||||||
@ -24,40 +22,31 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
public async ValueTask<uint> NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default)
|
public async ValueTask<uint> NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
|
// Swap the values if the range start is greater than the range end:
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||||
var tmp = rangeStart;
|
|
||||||
rangeStart = rangeEnd;
|
|
||||||
rangeEnd = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = rangeEnd - rangeStart;
|
var range = rangeEnd - rangeStart;
|
||||||
var distributedValue = await this.GetDistributedValue(cancel);
|
var distributedValue = await this.GetDistributedValue(cancel);
|
||||||
return (uint) ((distributedValue * range) + rangeStart);
|
return (uint) ((distributedValue * range) + rangeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, CancellationToken cancel = default(CancellationToken))
|
public async ValueTask<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
|
// Swap the values if the range start is greater than the range end:
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||||
var tmp = rangeStart;
|
|
||||||
rangeStart = rangeEnd;
|
|
||||||
rangeEnd = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = rangeEnd - rangeStart;
|
var range = rangeEnd - rangeStart;
|
||||||
var distributedValue = await this.GetDistributedValue(cancel);
|
var distributedValue = await this.GetDistributedValue(cancel);
|
||||||
return (ulong) ((distributedValue * range) + rangeStart);
|
return (ulong) ((distributedValue * range) + rangeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<float> NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default(CancellationToken))
|
public async ValueTask<float> NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
|
// Swap the values if the range start is greater than the range end:
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||||
var tmp = rangeStart;
|
|
||||||
rangeStart = rangeEnd;
|
|
||||||
rangeEnd = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = rangeEnd - rangeStart;
|
var range = rangeEnd - rangeStart;
|
||||||
var distributedValue = await this.GetDistributedValue(cancel);
|
var distributedValue = await this.GetDistributedValue(cancel);
|
||||||
@ -72,4 +61,3 @@ namespace FastRng.Distributions
|
|||||||
return number > above && number < below;
|
return number > above && number < below;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class ExponentialLa10 : Distribution
|
public sealed class ExponentialLa10 : Distribution
|
||||||
{
|
{
|
||||||
private const float LAMBDA = 10.0f;
|
private const float LAMBDA = 10.0f;
|
||||||
@ -13,4 +13,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x);
|
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class ExponentialLa5 : Distribution
|
public sealed class ExponentialLa5 : Distribution
|
||||||
{
|
{
|
||||||
private const float LAMBDA = 5.0f;
|
private const float LAMBDA = 5.0f;
|
||||||
@ -13,4 +13,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x);
|
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class GammaA5B15 : Distribution
|
public sealed class GammaA5B15 : Distribution
|
||||||
{
|
{
|
||||||
private const float ALPHA = 5.0f;
|
private const float ALPHA = 5.0f;
|
||||||
@ -23,4 +23,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
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 float ShapeFunction(float x) => CONSTANT * ((BETA_TO_THE_ALPHA * MathF.Pow(x, ALPHA - 1.0f) * MathF.Exp(-BETA * x)) / GAMMA_ALPHA);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public interface IDistribution
|
public interface IDistribution
|
||||||
{
|
{
|
||||||
public ValueTask<float> GetDistributedValue(CancellationToken token);
|
public ValueTask<float> GetDistributedValue(CancellationToken token);
|
||||||
@ -17,4 +17,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
public ValueTask<bool> HasDecisionBeenMade(float above, float below = 1.0f, CancellationToken cancel = default);
|
public ValueTask<bool> HasDecisionBeenMade(float above, float below = 1.0f, CancellationToken cancel = default);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class InverseExponentialLa10 : Distribution
|
public sealed class InverseExponentialLa10 : Distribution
|
||||||
{
|
{
|
||||||
private const float LAMBDA = 10.0f;
|
private const float LAMBDA = 10.0f;
|
||||||
@ -13,4 +13,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x);
|
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class InverseExponentialLa5 : Distribution
|
public sealed class InverseExponentialLa5 : Distribution
|
||||||
{
|
{
|
||||||
private const float LAMBDA = 5.0f;
|
private const float LAMBDA = 5.0f;
|
||||||
@ -13,4 +13,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x);
|
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class InverseGammaA3B05 : Distribution
|
public sealed class InverseGammaA3B05 : Distribution
|
||||||
{
|
{
|
||||||
private const float ALPHA = 3.0f;
|
private const float ALPHA = 3.0f;
|
||||||
@ -24,4 +24,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Pow(x, -ALPHA - 1.0f) * MathF.Exp(-BETA / x);
|
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Pow(x, -ALPHA - 1.0f) * MathF.Exp(-BETA / x);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class LaplaceB01M0 : Distribution
|
public sealed class LaplaceB01M0 : Distribution
|
||||||
{
|
{
|
||||||
private const float B = 0.1f;
|
private const float B = 0.1f;
|
||||||
@ -21,4 +21,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B);
|
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class LaplaceB01M05 : Distribution
|
public sealed class LaplaceB01M05 : Distribution
|
||||||
{
|
{
|
||||||
private const float B = 0.1f;
|
private const float B = 0.1f;
|
||||||
@ -21,4 +21,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B);
|
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class LogNormalS1M0 : Distribution
|
public sealed class LogNormalS1M0 : Distribution
|
||||||
{
|
{
|
||||||
private const float SIGMA = 1.0f;
|
private const float SIGMA = 1.0f;
|
||||||
@ -21,4 +21,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
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 float ShapeFunction(float x) => (CONSTANT / (x * FACTOR)) * MathF.Exp( -(MathF.Pow(MathF.Log(x) - MU, 2f) / (2f * MathF.Pow(SIGMA, 2f))));
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,17 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class NormalS02M05 : Distribution
|
public sealed class NormalS02M05 : Distribution
|
||||||
{
|
{
|
||||||
private const float SQRT_2_PI = 2.506628275f;
|
private const float SQRT_2_PI = 2.506628275f;
|
||||||
private const float STDDEV = 0.2f;
|
private const float STD_DEV = 0.2f;
|
||||||
private const float MEAN = 0.5f;
|
private const float MEAN = 0.5f;
|
||||||
|
|
||||||
public NormalS02M05(IRandom rng) : base(rng)
|
public NormalS02M05(IRandom rng) : base(rng)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private protected override float ShapeFunction(float x) => 1.0f / (STDDEV * SQRT_2_PI) * MathF.Exp(-0.5f * MathF.Pow((x - MEAN) / STDDEV, 2.0f));
|
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));
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class StudentTNu1 : Distribution
|
public sealed class StudentTNu1 : Distribution
|
||||||
{
|
{
|
||||||
private const float NU = 1.0f;
|
private const float NU = 1.0f;
|
||||||
@ -26,4 +26,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
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 float ShapeFunction(float x) => CONSTANT * MathF.Pow((DIVIDEND / DIVISOR) * MathF.Pow(1.0f + MathF.Pow(START + x * COMPRESS, 2f) / NU, EXPONENT), COMPRESS);
|
||||||
}
|
}
|
||||||
}
|
|
@ -2,58 +2,46 @@ using System;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class Uniform : IDistribution
|
public sealed class Uniform : IDistribution
|
||||||
{
|
{
|
||||||
private readonly IRandom rng;
|
private readonly IRandom rng;
|
||||||
|
|
||||||
public Uniform(IRandom rng)
|
public Uniform(IRandom rng)
|
||||||
{
|
{
|
||||||
if (rng == null)
|
this.rng = rng ?? throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed.");
|
||||||
throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed.");
|
|
||||||
|
|
||||||
this.rng = rng;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<float> GetDistributedValue(CancellationToken token = default) => await this.rng.GetUniform(token);
|
public async ValueTask<float> GetDistributedValue(CancellationToken token = default) => await this.rng.GetUniform(token);
|
||||||
|
|
||||||
public async ValueTask<uint> NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default)
|
public async ValueTask<uint> NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
|
// Swap the values if the range start is greater than the range end:
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||||
var tmp = rangeStart;
|
|
||||||
rangeStart = rangeEnd;
|
|
||||||
rangeEnd = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = rangeEnd - rangeStart;
|
var range = rangeEnd - rangeStart;
|
||||||
var distributedValue = await this.GetDistributedValue(cancel);
|
var distributedValue = await this.GetDistributedValue(cancel);
|
||||||
return (uint) ((distributedValue * range) + rangeStart);
|
return (uint) ((distributedValue * range) + rangeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, CancellationToken cancel = default(CancellationToken))
|
public async ValueTask<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
|
// Swap the values if the range start is greater than the range end:
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||||
var tmp = rangeStart;
|
|
||||||
rangeStart = rangeEnd;
|
|
||||||
rangeEnd = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = rangeEnd - rangeStart;
|
var range = rangeEnd - rangeStart;
|
||||||
var distributedValue = await this.GetDistributedValue(cancel);
|
var distributedValue = await this.GetDistributedValue(cancel);
|
||||||
return (ulong) ((distributedValue * range) + rangeStart);
|
return (ulong) ((distributedValue * range) + rangeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<float> NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default(CancellationToken))
|
public async ValueTask<float> NextNumber(float rangeStart, float rangeEnd, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
|
// Swap the values if the range start is greater than the range end:
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||||
var tmp = rangeStart;
|
|
||||||
rangeStart = rangeEnd;
|
|
||||||
rangeEnd = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = rangeEnd - rangeStart;
|
var range = rangeEnd - rangeStart;
|
||||||
var distributedValue = await this.GetDistributedValue(cancel);
|
var distributedValue = await this.GetDistributedValue(cancel);
|
||||||
@ -68,4 +56,3 @@ namespace FastRng.Distributions
|
|||||||
return number > above && number < below;
|
return number > above && number < below;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng.Distributions
|
namespace FastRng.Distributions;
|
||||||
{
|
|
||||||
public sealed class WeibullK05La1 : Distribution
|
public sealed class WeibullK05La1 : Distribution
|
||||||
{
|
{
|
||||||
private const float K = 0.5f;
|
private const float K = 0.5f;
|
||||||
@ -14,4 +14,3 @@ namespace FastRng.Distributions
|
|||||||
|
|
||||||
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 float ShapeFunction(float x) => CONSTANT * ( (K / LAMBDA) * MathF.Pow(x / LAMBDA, K - 1.0f) * MathF.Exp(-MathF.Pow(x/LAMBDA, K)));
|
||||||
}
|
}
|
||||||
}
|
|
@ -2,8 +2,8 @@ using System;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FastRng
|
namespace FastRng;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for random number generators.
|
/// Interface for random number generators.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -20,4 +20,3 @@ namespace FastRng
|
|||||||
/// <param name="cancel">An optional cancellation token.</param>
|
/// <param name="cancel">An optional cancellation token.</param>
|
||||||
public ValueTask<float> GetUniform(CancellationToken cancel = default);
|
public ValueTask<float> GetUniform(CancellationToken cancel = default);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace FastRng
|
namespace FastRng;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides some mathematical function, which are not available within in the .NET framework.
|
/// Provides some mathematical function, which are not available within in the .NET framework.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -40,14 +40,14 @@ namespace FastRng
|
|||||||
A8 / (z + 6) +
|
A8 / (z + 6) +
|
||||||
A9 / (z + 7);
|
A9 / (z + 7);
|
||||||
|
|
||||||
return MathTools.SQRT_2 * MathTools.SQRT_PI * MathF.Pow(t, z - 0.5f) * MathF.Exp(-t) * x;
|
return SQRT_2 * SQRT_PI * MathF.Pow(t, z - 0.5f) * MathF.Exp(-t) * x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mathematical factorial function for floating-point numbers.
|
/// The mathematical factorial function for floating-point numbers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">The value, for which you want to know the factorial.</param>
|
/// <param name="x">The value, for which you want to know the factorial.</param>
|
||||||
public static float Factorial(float x) => MathTools.Gamma(x + 1.0f);
|
public static float Factorial(float x) => Gamma(x + 1.0f);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mathematical factorial function for integer numbers.
|
/// The mathematical factorial function for integer numbers.
|
||||||
@ -77,7 +77,6 @@ namespace FastRng
|
|||||||
if(x < 0)
|
if(x < 0)
|
||||||
throw new ArgumentOutOfRangeException(nameof(x), "Given value must be greater as zero.");
|
throw new ArgumentOutOfRangeException(nameof(x), "Given value must be greater as zero.");
|
||||||
|
|
||||||
return MathTools.Factorial((uint) x);
|
return Factorial((uint) x);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,8 +4,8 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FastRng
|
namespace FastRng;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A fast multi-threaded pseudo random number generator.
|
/// A fast multi-threaded pseudo random number generator.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,16 +37,16 @@ namespace FastRng
|
|||||||
private const int QUEUE_SIZE = 2;
|
private const int QUEUE_SIZE = 2;
|
||||||
|
|
||||||
// Gets used to stop the producer threads:
|
// Gets used to stop the producer threads:
|
||||||
private readonly CancellationTokenSource producerTokenSource = new CancellationTokenSource();
|
private readonly CancellationTokenSource producerTokenSource = new();
|
||||||
|
|
||||||
// The time a thread waits e.g. to check if the queue needs a new buffer:
|
// The time a thread waits e.g. to check if the queue needs a new buffer:
|
||||||
private readonly TimeSpan waiter = TimeSpan.FromMilliseconds(10);
|
private readonly TimeSpan waiter = TimeSpan.FromMilliseconds(10);
|
||||||
|
|
||||||
// The first queue, where to store buffers of random uint numbers:
|
// The first queue, where to store buffers of random uint numbers:
|
||||||
private readonly ConcurrentQueue<uint[]> queueIntegers = new ConcurrentQueue<uint[]>();
|
private readonly ConcurrentQueue<uint[]> queueIntegers = new();
|
||||||
|
|
||||||
// The second queue, where to store buffers of uniform random floating point numbers:
|
// The second queue, where to store buffers of uniform random floating point numbers:
|
||||||
private readonly ConcurrentQueue<float[]> queueFloats = new ConcurrentQueue<float[]>();
|
private readonly ConcurrentQueue<float[]> queueFloats = new();
|
||||||
|
|
||||||
// The uint producer thread:
|
// The uint producer thread:
|
||||||
private Thread producerRandomUint;
|
private Thread producerRandomUint;
|
||||||
@ -354,4 +354,3 @@ namespace FastRng
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
|
@ -3,8 +3,8 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FastRng.Distributions;
|
using FastRng.Distributions;
|
||||||
|
|
||||||
namespace FastRng
|
namespace FastRng;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ShapeFitter is a rejection sampler, cf. https://en.wikipedia.org/wiki/Rejection_sampling
|
/// ShapeFitter is a rejection sampler, cf. https://en.wikipedia.org/wiki/Rejection_sampling
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -75,4 +75,3 @@ namespace FastRng
|
|||||||
return float.NaN;
|
return float.NaN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -6,8 +6,8 @@ using NUnit.Framework;
|
|||||||
using Uniform = FastRng.Distributions.Uniform;
|
using Uniform = FastRng.Distributions.Uniform;
|
||||||
using WeibullK05La1 = FastRng.Distributions.WeibullK05La1;
|
using WeibullK05La1 = FastRng.Distributions.WeibullK05La1;
|
||||||
|
|
||||||
namespace FastRngTests
|
namespace FastRngTests;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class DecisionTester
|
public class DecisionTester
|
||||||
{
|
{
|
||||||
@ -59,4 +59,3 @@ namespace FastRngTests
|
|||||||
Assert.That(max - min, Is.LessThanOrEqualTo(2_800));
|
Assert.That(max - min, Is.LessThanOrEqualTo(2_800));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class BetaA2B2
|
public class BetaA2B2
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA2B2(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA2B2(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class BetaA2B5
|
public class BetaA2B5
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA2B5(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA2B5(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class BetaA5B2
|
public class BetaA5B2
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA5B2(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA5B2(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class CauchyLorentzX0
|
public class CauchyLorentzX0
|
||||||
{
|
{
|
||||||
@ -84,4 +84,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.CauchyLorentzX0(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.CauchyLorentzX0(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class CauchyLorentzX1
|
public class CauchyLorentzX1
|
||||||
{
|
{
|
||||||
@ -84,4 +84,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.CauchyLorentzX1(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.CauchyLorentzX1(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ChiSquareK1
|
public class ChiSquareK1
|
||||||
{
|
{
|
||||||
@ -84,4 +84,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK1(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK1(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ChiSquareK10
|
public class ChiSquareK10
|
||||||
{
|
{
|
||||||
@ -84,4 +84,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK10(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK10(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ChiSquareK4
|
public class ChiSquareK4
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK4(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK4(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ExponentialLa10
|
public class ExponentialLa10
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ExponentialLa10(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ExponentialLa10(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ExponentialLa5
|
public class ExponentialLa5
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ExponentialLa5(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ExponentialLa5(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GammaA5B15
|
public class GammaA5B15
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.GammaA5B15(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.GammaA5B15(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class InverseExponentialLa10
|
public class InverseExponentialLa10
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseExponentialLa10(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseExponentialLa10(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class InverseExponentialLa5
|
public class InverseExponentialLa5
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseExponentialLa5(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseExponentialLa5(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class InverseGammaA3B05
|
public class InverseGammaA3B05
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseGammaA3B05(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseGammaA3B05(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class LaplaceB01M0
|
public class LaplaceB01M0
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LaplaceB01M0(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LaplaceB01M0(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class LaplaceB01M05
|
public class LaplaceB01M05
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LaplaceB01M05(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LaplaceB01M05(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class LogNormalS1M0
|
public class LogNormalS1M0
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LogNormalS1M0(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LogNormalS1M0(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class NormalS02M05
|
public class NormalS02M05
|
||||||
{
|
{
|
||||||
@ -77,4 +77,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.NormalS02M05(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.NormalS02M05(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class StudentTNu1
|
public class StudentTNu1
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.StudentTNu1(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.StudentTNu1(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class Uniform
|
public class Uniform
|
||||||
{
|
{
|
||||||
@ -294,4 +294,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.Uniform(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.Uniform(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -5,8 +5,8 @@ using System.Threading.Tasks;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests.Distributions
|
namespace FastRngTests.Distributions;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class WeibullK05La1
|
public class WeibullK05La1
|
||||||
{
|
{
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests.Distributions
|
|||||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.WeibullK05La1(null));
|
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.WeibullK05La1(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -3,8 +3,8 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace FastRngTests
|
namespace FastRngTests;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public sealed class FrequencyAnalysis
|
public sealed class FrequencyAnalysis
|
||||||
{
|
{
|
||||||
@ -46,7 +46,7 @@ namespace FastRngTests
|
|||||||
public float[] NormalizeAndPlotEvents(Action<string> writer)
|
public float[] NormalizeAndPlotEvents(Action<string> writer)
|
||||||
{
|
{
|
||||||
var result = this.Normalize();
|
var result = this.Normalize();
|
||||||
FrequencyAnalysis.Plot(result, writer, "Event Distribution");
|
Plot(result, writer, "Event Distribution");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ namespace FastRngTests
|
|||||||
public void PlotOccurence(Action<string> writer)
|
public void PlotOccurence(Action<string> writer)
|
||||||
{
|
{
|
||||||
var data = this.data.Select(n => n > 0f ? 1.0f : 0.0f).ToArray();
|
var data = this.data.Select(n => n > 0f ? 1.0f : 0.0f).ToArray();
|
||||||
FrequencyAnalysis.Plot(data, writer, "Occurrence Distribution");
|
Plot(data, writer, "Occurrence Distribution");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Plot(float[] data, Action<string> writer, string name)
|
private static void Plot(float[] data, Action<string> writer, string name)
|
||||||
@ -81,4 +81,3 @@ namespace FastRngTests
|
|||||||
writer.Invoke(string.Empty);
|
writer.Invoke(string.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -3,8 +3,8 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using FastRng;
|
using FastRng;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests
|
namespace FastRngTests;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class MathToolsTests
|
public class MathToolsTests
|
||||||
{
|
{
|
||||||
@ -338,4 +338,3 @@ namespace FastRngTests
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
|
@ -6,8 +6,8 @@ using FastRng;
|
|||||||
using FastRng.Distributions;
|
using FastRng.Distributions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests
|
namespace FastRngTests;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class MultiThreadedRngTests
|
public class MultiThreadedRngTests
|
||||||
{
|
{
|
||||||
@ -622,4 +622,3 @@ namespace FastRngTests
|
|||||||
Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(56));
|
Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(56));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -9,8 +9,8 @@ using MathNet.Numerics.Distributions;
|
|||||||
using MathNet.Numerics.Random;
|
using MathNet.Numerics.Random;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace FastRngTests
|
namespace FastRngTests;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class PerformanceTests
|
public class PerformanceTests
|
||||||
{
|
{
|
||||||
@ -134,4 +134,3 @@ namespace FastRngTests
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace FastRngTests
|
namespace FastRngTests;
|
||||||
{
|
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
internal sealed class RunningStatistics
|
internal sealed class RunningStatistics
|
||||||
{
|
{
|
||||||
@ -11,11 +11,7 @@ namespace FastRngTests
|
|||||||
private float nextM;
|
private float nextM;
|
||||||
private float nextS;
|
private float nextS;
|
||||||
|
|
||||||
public RunningStatistics()
|
private int NumberRecords { get; set; } = 0;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public int NumberRecords { get; private set; } = 0;
|
|
||||||
|
|
||||||
public void Clear() => this.NumberRecords = 0;
|
public void Clear() => this.NumberRecords = 0;
|
||||||
|
|
||||||
@ -46,4 +42,3 @@ namespace FastRngTests
|
|||||||
|
|
||||||
public float StandardDeviation => MathF.Sqrt(this.Variance);
|
public float StandardDeviation => MathF.Sqrt(this.Variance);
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
namespace FastRngTests
|
namespace FastRngTests;
|
||||||
{
|
|
||||||
public class TestCategories
|
public static class TestCategories
|
||||||
{
|
{
|
||||||
public const string COVER = "cover";
|
public const string COVER = "cover";
|
||||||
public const string PERFORMANCE = "performance";
|
public const string PERFORMANCE = "performance";
|
||||||
@ -8,4 +8,3 @@ namespace FastRngTests
|
|||||||
public const string EXAMPLE = "example";
|
public const string EXAMPLE = "example";
|
||||||
public const string LONG_RUNNING = "long running";
|
public const string LONG_RUNNING = "long running";
|
||||||
}
|
}
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user