Applied .NET 7 syntax or feature changes
This commit is contained in:
parent
38764d5d97
commit
e8cf1284d7
@ -1,9 +1,9 @@
|
||||
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 BETA = 2f;
|
||||
private const float CONSTANT = 4f;
|
||||
@ -13,5 +13,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 BETA = 5f;
|
||||
private const float CONSTANT = 12.2f;
|
||||
@ -13,5 +13,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 BETA = 2f;
|
||||
private const float CONSTANT = 12.2f;
|
||||
@ -13,5 +13,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow(x, ALPHA - 1f) * MathF.Pow(1f - x, BETA - 1f);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 SCALE = 0.1f;
|
||||
private const float MEDIAN = 0.0f;
|
||||
@ -13,5 +13,4 @@ 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)));
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 SCALE = 0.1f;
|
||||
private const float MEDIAN = 1.0f;
|
||||
@ -13,5 +13,4 @@ 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)));
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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_HALF = K * 0.5f;
|
||||
private const float K_HALF_MINUS_ONE = K_HALF - 1.0f;
|
||||
@ -23,5 +23,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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_HALF = K * 0.5f;
|
||||
private const float K_HALF_MINUS_ONE = K_HALF - 1.0f;
|
||||
@ -23,5 +23,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * ((MathF.Pow(x, K_HALF_MINUS_ONE) * MathF.Exp(-x * 0.5f)) / DIVISOR);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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_HALF = K * 0.5f;
|
||||
private const float K_HALF_MINUS_ONE = K_HALF - 1.0f;
|
||||
@ -23,5 +23,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
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.Tasks;
|
||||
|
||||
namespace FastRng.Distributions
|
||||
namespace FastRng.Distributions;
|
||||
|
||||
public abstract class Distribution : IDistribution
|
||||
{
|
||||
public abstract class Distribution : IDistribution
|
||||
{
|
||||
private readonly ShapeFitter fitter;
|
||||
private readonly IRandom random;
|
||||
|
||||
protected Distribution(IRandom rng)
|
||||
{
|
||||
if (rng == null)
|
||||
throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed.");
|
||||
|
||||
this.random = rng;
|
||||
this.fitter = new ShapeFitter(this.ShapeFunction, this.random, 100);
|
||||
this.fitter = new ShapeFitter(this.ShapeFunction, rng, 100);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Swap the values if the range start is greater than the range end:
|
||||
if (rangeStart > rangeEnd)
|
||||
{
|
||||
var tmp = rangeStart;
|
||||
rangeStart = rangeEnd;
|
||||
rangeEnd = tmp;
|
||||
}
|
||||
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||
|
||||
var range = rangeEnd - rangeStart;
|
||||
var distributedValue = await this.GetDistributedValue(cancel);
|
||||
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)
|
||||
{
|
||||
var tmp = rangeStart;
|
||||
rangeStart = rangeEnd;
|
||||
rangeEnd = tmp;
|
||||
}
|
||||
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||
|
||||
var range = rangeEnd - rangeStart;
|
||||
var distributedValue = await this.GetDistributedValue(cancel);
|
||||
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)
|
||||
{
|
||||
var tmp = rangeStart;
|
||||
rangeStart = rangeEnd;
|
||||
rangeEnd = tmp;
|
||||
}
|
||||
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||
|
||||
var range = rangeEnd - rangeStart;
|
||||
var distributedValue = await this.GetDistributedValue(cancel);
|
||||
@ -71,5 +60,4 @@ namespace FastRng.Distributions
|
||||
var number = await this.NextNumber(cancel);
|
||||
return number > above && number < below;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 CONSTANT = 0.1106f;
|
||||
|
||||
@ -12,5 +12,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 CONSTANT = 0.2103f;
|
||||
|
||||
@ -12,5 +12,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 BETA = 15.0f;
|
||||
private const float CONSTANT = 0.341344210715475f;
|
||||
@ -22,5 +22,4 @@ 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);
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastRng.Distributions
|
||||
namespace FastRng.Distributions;
|
||||
|
||||
public interface IDistribution
|
||||
{
|
||||
public interface IDistribution
|
||||
{
|
||||
public ValueTask<float> GetDistributedValue(CancellationToken token);
|
||||
|
||||
public ValueTask<uint> NextNumber(uint rangeStart, uint rangeEnd, CancellationToken cancel = default);
|
||||
@ -16,5 +16,4 @@ namespace FastRng.Distributions
|
||||
public ValueTask<float> NextNumber(CancellationToken cancel = default);
|
||||
|
||||
public ValueTask<bool> HasDecisionBeenMade(float above, float below = 1.0f, CancellationToken cancel = default);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 CONSTANT = 4.539992976248453e-06f;
|
||||
|
||||
@ -12,5 +12,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 CONSTANT = 0.001347589399817f;
|
||||
|
||||
@ -12,5 +12,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 BETA = 0.5f;
|
||||
private const float CONSTANT = 0.213922656884911f;
|
||||
@ -23,5 +23,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Pow(x, -ALPHA - 1.0f) * MathF.Exp(-BETA / x);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 MU = 0.0f;
|
||||
private const float CONSTANT = 0.221034183615129f;
|
||||
@ -20,5 +20,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 MU = 0.5f;
|
||||
private const float CONSTANT = 0.2f;
|
||||
@ -20,5 +20,4 @@ namespace FastRng.Distributions
|
||||
}
|
||||
|
||||
private protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 MU = 0.0f;
|
||||
private const float CONSTANT = 1.51998658387455f;
|
||||
@ -20,5 +20,4 @@ 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))));
|
||||
}
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
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 STDDEV = 0.2f;
|
||||
private const float STD_DEV = 0.2f;
|
||||
private const float MEAN = 0.5f;
|
||||
|
||||
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,9 +1,9 @@
|
||||
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 START = 0.0f;
|
||||
private const float COMPRESS = 1.0f;
|
||||
@ -25,5 +25,4 @@ 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);
|
||||
}
|
||||
}
|
@ -2,58 +2,46 @@ using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastRng.Distributions
|
||||
namespace FastRng.Distributions;
|
||||
|
||||
public sealed class Uniform : IDistribution
|
||||
{
|
||||
public sealed class Uniform : IDistribution
|
||||
{
|
||||
private readonly IRandom rng;
|
||||
|
||||
public Uniform(IRandom rng)
|
||||
{
|
||||
if (rng == null)
|
||||
throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed.");
|
||||
|
||||
this.rng = rng;
|
||||
this.rng = rng ?? throw new ArgumentNullException(nameof(rng), "An IRandom implementation is needed.");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Swap the values if the range start is greater than the range end:
|
||||
if (rangeStart > rangeEnd)
|
||||
{
|
||||
var tmp = rangeStart;
|
||||
rangeStart = rangeEnd;
|
||||
rangeEnd = tmp;
|
||||
}
|
||||
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||
|
||||
var range = rangeEnd - rangeStart;
|
||||
var distributedValue = await this.GetDistributedValue(cancel);
|
||||
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)
|
||||
{
|
||||
var tmp = rangeStart;
|
||||
rangeStart = rangeEnd;
|
||||
rangeEnd = tmp;
|
||||
}
|
||||
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||
|
||||
var range = rangeEnd - rangeStart;
|
||||
var distributedValue = await this.GetDistributedValue(cancel);
|
||||
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)
|
||||
{
|
||||
var tmp = rangeStart;
|
||||
rangeStart = rangeEnd;
|
||||
rangeEnd = tmp;
|
||||
}
|
||||
(rangeStart, rangeEnd) = (rangeEnd, rangeStart);
|
||||
|
||||
var range = rangeEnd - rangeStart;
|
||||
var distributedValue = await this.GetDistributedValue(cancel);
|
||||
@ -67,5 +55,4 @@ namespace FastRng.Distributions
|
||||
var number = await this.NextNumber(cancel);
|
||||
return number > above && number < below;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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 LAMBDA = 1.0f;
|
||||
private const float CONSTANT = 0.221034183615129f;
|
||||
@ -13,5 +13,4 @@ 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)));
|
||||
}
|
||||
}
|
@ -2,13 +2,13 @@ using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastRng
|
||||
namespace FastRng;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for random number generators.
|
||||
/// </summary>
|
||||
public interface IRandom : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for random number generators.
|
||||
/// </summary>
|
||||
public interface IRandom : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a uniform distributed pseudo-random number from the interval (0,1].
|
||||
/// This means, the result 0 is impossible, whereas 1 is possible.
|
||||
@ -19,5 +19,4 @@ namespace FastRng
|
||||
/// </remarks>
|
||||
/// <param name="cancel">An optional cancellation token.</param>
|
||||
public ValueTask<float> GetUniform(CancellationToken cancel = default);
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace FastRng
|
||||
namespace FastRng;
|
||||
|
||||
/// <summary>
|
||||
/// Provides some mathematical function, which are not available within in the .NET framework.
|
||||
/// </summary>
|
||||
public static class MathTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides some mathematical function, which are not available within in the .NET framework.
|
||||
/// </summary>
|
||||
public static class MathTools
|
||||
{
|
||||
private static readonly float SQRT_2 = MathF.Sqrt(2.0f);
|
||||
private static readonly float SQRT_PI = MathF.Sqrt(MathF.PI);
|
||||
|
||||
@ -40,14 +40,14 @@ namespace FastRng
|
||||
A8 / (z + 6) +
|
||||
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>
|
||||
/// The mathematical factorial function for floating-point numbers.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// The mathematical factorial function for integer numbers.
|
||||
@ -77,7 +77,6 @@ namespace FastRng
|
||||
if(x < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(x), "Given value must be greater as zero.");
|
||||
|
||||
return MathTools.Factorial((uint) x);
|
||||
}
|
||||
return Factorial((uint) x);
|
||||
}
|
||||
}
|
@ -4,49 +4,49 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FastRng
|
||||
namespace FastRng;
|
||||
|
||||
/// <summary>
|
||||
/// A fast multi-threaded pseudo random number generator.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Please note, that Math.NET's (https://www.mathdotnet.com/) random number generator is in some situations faster.
|
||||
/// Unlike Math.NET, MultiThreadedRng is multi-threaded and async. Consumers can await the next number without
|
||||
/// blocking resources. Additionally, consumers can use a token to cancel e.g. timeout an operation as well.<br/><br/>
|
||||
///
|
||||
/// MultiThreadedRng using a shape fitter (a rejection sampler) to enforce arbitrary shapes of probabilities for
|
||||
/// desired distributions. By using the shape fitter, it is even easy to define discontinuous, arbitrary functions
|
||||
/// as shapes. Any consumer can define and use own distributions.<br/><br/>
|
||||
///
|
||||
/// This class uses the George Marsaglia's MWC algorithm. The algorithm's implementation based loosely on John D.
|
||||
/// Cook's (johndcook.com) implementation (https://www.codeproject.com/Articles/25172/Simple-Random-Number-Generation).
|
||||
/// Thanks John for the inspiration.<br/><br/>
|
||||
///
|
||||
/// Please notice: When using the debug environment, MultiThreadedRng uses a smaller buffer size. Please ensure,
|
||||
/// that the production environment uses a release build, though.
|
||||
/// </remarks>
|
||||
public sealed class MultiThreadedRng : IRandom, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// A fast multi-threaded pseudo random number generator.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Please note, that Math.NET's (https://www.mathdotnet.com/) random number generator is in some situations faster.
|
||||
/// Unlike Math.NET, MultiThreadedRng is multi-threaded and async. Consumers can await the next number without
|
||||
/// blocking resources. Additionally, consumers can use a token to cancel e.g. timeout an operation as well.<br/><br/>
|
||||
///
|
||||
/// MultiThreadedRng using a shape fitter (a rejection sampler) to enforce arbitrary shapes of probabilities for
|
||||
/// desired distributions. By using the shape fitter, it is even easy to define discontinuous, arbitrary functions
|
||||
/// as shapes. Any consumer can define and use own distributions.<br/><br/>
|
||||
///
|
||||
/// This class uses the George Marsaglia's MWC algorithm. The algorithm's implementation based loosely on John D.
|
||||
/// Cook's (johndcook.com) implementation (https://www.codeproject.com/Articles/25172/Simple-Random-Number-Generation).
|
||||
/// Thanks John for the inspiration.<br/><br/>
|
||||
///
|
||||
/// Please notice: When using the debug environment, MultiThreadedRng uses a smaller buffer size. Please ensure,
|
||||
/// that the production environment uses a release build, though.
|
||||
/// </remarks>
|
||||
public sealed class MultiThreadedRng : IRandom, IDisposable
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
private const int BUFFER_SIZE = 10_000;
|
||||
#else
|
||||
#else
|
||||
private const int BUFFER_SIZE = 1_000_000;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// The queue size means, how many buffer we store in a queue at the same time:
|
||||
private const int QUEUE_SIZE = 2;
|
||||
|
||||
// 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:
|
||||
private readonly TimeSpan waiter = TimeSpan.FromMilliseconds(10);
|
||||
|
||||
// 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:
|
||||
private readonly ConcurrentQueue<float[]> queueFloats = new ConcurrentQueue<float[]>();
|
||||
private readonly ConcurrentQueue<float[]> queueFloats = new();
|
||||
|
||||
// The uint producer thread:
|
||||
private Thread producerRandomUint;
|
||||
@ -353,5 +353,4 @@ namespace FastRng
|
||||
public void Dispose() => this.StopProducer();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -3,13 +3,13 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FastRng.Distributions;
|
||||
|
||||
namespace FastRng
|
||||
namespace FastRng;
|
||||
|
||||
/// <summary>
|
||||
/// ShapeFitter is a rejection sampler, cf. https://en.wikipedia.org/wiki/Rejection_sampling
|
||||
/// </summary>
|
||||
public sealed class ShapeFitter
|
||||
{
|
||||
/// <summary>
|
||||
/// ShapeFitter is a rejection sampler, cf. https://en.wikipedia.org/wiki/Rejection_sampling
|
||||
/// </summary>
|
||||
public sealed class ShapeFitter
|
||||
{
|
||||
private readonly float[] probabilities;
|
||||
private readonly IRandom rng;
|
||||
private readonly float max;
|
||||
@ -74,5 +74,4 @@ namespace FastRng
|
||||
|
||||
return float.NaN;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,11 +6,11 @@ using NUnit.Framework;
|
||||
using Uniform = FastRng.Distributions.Uniform;
|
||||
using WeibullK05La1 = FastRng.Distributions.WeibullK05La1;
|
||||
|
||||
namespace FastRngTests
|
||||
namespace FastRngTests;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DecisionTester
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DecisionTester
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -58,5 +58,4 @@ namespace FastRngTests
|
||||
TestContext.WriteLine($"Coin tosses: a={neededCoinTossesA}, b={neededCoinTossesB}, c={neededCoinTossesC}");
|
||||
Assert.That(max - min, Is.LessThanOrEqualTo(2_800));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BetaA2B2
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BetaA2B2
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA2B2(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BetaA2B5
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BetaA2B5
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA2B5(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BetaA5B2
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BetaA5B2
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.BetaA5B2(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CauchyLorentzX0
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CauchyLorentzX0
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -83,5 +83,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.CauchyLorentzX0(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CauchyLorentzX1
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CauchyLorentzX1
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -83,5 +83,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.CauchyLorentzX1(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChiSquareK1
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChiSquareK1
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -83,5 +83,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK1(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChiSquareK10
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChiSquareK10
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -83,5 +83,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK10(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChiSquareK4
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChiSquareK4
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ChiSquareK4(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ExponentialLa10
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ExponentialLa10
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ExponentialLa10(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ExponentialLa5
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ExponentialLa5
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.ExponentialLa5(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GammaA5B15
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GammaA5B15
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.GammaA5B15(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InverseExponentialLa10
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InverseExponentialLa10
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseExponentialLa10(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InverseExponentialLa5
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InverseExponentialLa5
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseExponentialLa5(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InverseGammaA3B05
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InverseGammaA3B05
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.InverseGammaA3B05(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LaplaceB01M0
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LaplaceB01M0
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LaplaceB01M0(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LaplaceB01M05
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LaplaceB01M05
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LaplaceB01M05(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LogNormalS1M0
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LogNormalS1M0
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.LogNormalS1M0(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class NormalS02M05
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class NormalS02M05
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -76,5 +76,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.NormalS02M05(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StudentTNu1
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StudentTNu1
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.StudentTNu1(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class Uniform
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class Uniform
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -293,5 +293,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.Uniform(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests.Distributions
|
||||
namespace FastRngTests.Distributions;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WeibullK05La1
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WeibullK05La1
|
||||
{
|
||||
[Test]
|
||||
[Category(TestCategories.COVER)]
|
||||
[Category(TestCategories.NORMAL)]
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests.Distributions
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new FastRng.Distributions.WeibullK05La1(null));
|
||||
}
|
||||
}
|
||||
}
|
@ -3,11 +3,11 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace FastRngTests
|
||||
namespace FastRngTests;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class FrequencyAnalysis
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class FrequencyAnalysis
|
||||
{
|
||||
private readonly uint[] data;
|
||||
|
||||
public FrequencyAnalysis(int samples = 100)
|
||||
@ -46,7 +46,7 @@ namespace FastRngTests
|
||||
public float[] NormalizeAndPlotEvents(Action<string> writer)
|
||||
{
|
||||
var result = this.Normalize();
|
||||
FrequencyAnalysis.Plot(result, writer, "Event Distribution");
|
||||
Plot(result, writer, "Event Distribution");
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace FastRngTests
|
||||
public void PlotOccurence(Action<string> writer)
|
||||
{
|
||||
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)
|
||||
@ -80,5 +80,4 @@ namespace FastRngTests
|
||||
writer.Invoke(name);
|
||||
writer.Invoke(string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,11 +3,11 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using FastRng;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests
|
||||
namespace FastRngTests;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MathToolsTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MathToolsTests
|
||||
{
|
||||
#region Gamma
|
||||
|
||||
[Test]
|
||||
@ -337,5 +337,4 @@ namespace FastRngTests
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -6,11 +6,11 @@ using FastRng;
|
||||
using FastRng.Distributions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests
|
||||
namespace FastRngTests;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MultiThreadedRngTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MultiThreadedRngTests
|
||||
{
|
||||
private readonly IRandom rng = new MultiThreadedRng();
|
||||
|
||||
[Test]
|
||||
@ -621,5 +621,4 @@ namespace FastRngTests
|
||||
Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(4));
|
||||
Assert.That(await dist.NextNumber(1, 100), Is.EqualTo(56));
|
||||
}
|
||||
}
|
||||
}
|
@ -9,11 +9,11 @@ using MathNet.Numerics.Distributions;
|
||||
using MathNet.Numerics.Random;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace FastRngTests
|
||||
namespace FastRngTests;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PerformanceTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PerformanceTests
|
||||
{
|
||||
#region FastRng
|
||||
|
||||
[Test]
|
||||
@ -133,5 +133,4 @@ namespace FastRngTests
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,21 +1,17 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace FastRngTests
|
||||
namespace FastRngTests;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal sealed class RunningStatistics
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal sealed class RunningStatistics
|
||||
{
|
||||
private float previousM;
|
||||
private float previousS;
|
||||
private float nextM;
|
||||
private float nextS;
|
||||
|
||||
public RunningStatistics()
|
||||
{
|
||||
}
|
||||
|
||||
public int NumberRecords { get; private set; } = 0;
|
||||
private int NumberRecords { get; set; } = 0;
|
||||
|
||||
public void Clear() => this.NumberRecords = 0;
|
||||
|
||||
@ -45,5 +41,4 @@ namespace FastRngTests
|
||||
public float Variance => this.NumberRecords > 1 ? this.nextS / (this.NumberRecords - 1f) : 0.0f;
|
||||
|
||||
public float StandardDeviation => MathF.Sqrt(this.Variance);
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
namespace FastRngTests
|
||||
namespace FastRngTests;
|
||||
|
||||
public static class TestCategories
|
||||
{
|
||||
public class TestCategories
|
||||
{
|
||||
public const string COVER = "cover";
|
||||
public const string PERFORMANCE = "performance";
|
||||
public const string NORMAL = "normal";
|
||||
public const string EXAMPLE = "example";
|
||||
public const string LONG_RUNNING = "long running";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user