FastRng/FastRng/IRandom.cs
2024-05-29 11:39:08 +02:00

46 lines
1.9 KiB
C#

using System;
using System.Numerics;
using System.Threading;
namespace FastRng;
/// <summary>
/// Interface for random number generators.
/// </summary>
public interface IRandom<TNum> : IDisposable where TNum : IFloatingPointIeee754<TNum>
{
/// <summary>
/// Returns a uniform distributed pseudo-random number from the interval (0,1].
/// This means, the result 0 is impossible, whereas 1 is possible.
/// </summary>
/// <remarks>
/// This method is thread-safe. You can consume numbers from the same generator
/// by using multiple threads at the same time.
/// </remarks>
public TNum GetUniform(CancellationToken cancel = default);
/// <summary>
/// Get a uniform distributed pseudo-random number from the interval [0, max).
/// </summary>
/// <remarks>
/// This method is thread-safe. You can consume numbers from the same generator
/// by using multiple threads at the same time.
/// </remarks>
/// <param name="max">The maximum value (exclusive). The max value returned will be max - 1.</param>
/// <param name="cancel">The cancellation token.</param>
/// <returns>A pseudo-random number from the interval [0, max).</returns>
public int GetUniformInt(int max, CancellationToken cancel = default);
/// <summary>
/// Get a uniform distributed pseudo-random number from the interval [min, max).
/// </summary>
/// <remarks>
/// This method is thread-safe. You can consume numbers from the same generator
/// by using multiple threads at the same time.
/// </remarks>
/// <param name="min">The minimum value (inclusive).</param>
/// <param name="max">The maximum value (exclusive). The max value returned will be max - 1.</param>
/// <param name="cancel">The cancellation token.</param>
/// <returns>A pseudo-random number from the interval [min, max).</returns>
public int GetUniformInt(int min, int max, CancellationToken cancel = default);
}