2020-11-07 14:46:00 +00:00
|
|
|
using System;
|
2023-07-07 12:41:01 +00:00
|
|
|
using System.Numerics;
|
2020-10-31 22:27:18 +00:00
|
|
|
using System.Threading;
|
|
|
|
|
|
2023-07-06 08:26:12 +00:00
|
|
|
namespace FastRng;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interface for random number generators.
|
|
|
|
|
/// </summary>
|
2023-07-07 12:41:01 +00:00
|
|
|
public interface IRandom<TNum> : IDisposable where TNum : IFloatingPointIeee754<TNum>
|
2020-10-31 22:27:18 +00:00
|
|
|
{
|
2020-11-08 15:22:40 +00:00
|
|
|
/// <summary>
|
2023-07-06 08:26:12 +00:00
|
|
|
/// Returns a uniform distributed pseudo-random number from the interval (0,1].
|
|
|
|
|
/// This means, the result 0 is impossible, whereas 1 is possible.
|
2020-11-08 15:22:40 +00:00
|
|
|
/// </summary>
|
2023-07-06 08:26:12 +00:00
|
|
|
/// <remarks>
|
|
|
|
|
/// This method is thread-safe. You can consume numbers from the same generator
|
|
|
|
|
/// by using multiple threads at the same time.
|
|
|
|
|
/// </remarks>
|
2023-07-10 14:38:25 +00:00
|
|
|
public TNum GetUniform(CancellationToken cancel = default);
|
2024-05-29 09:39:08 +00:00
|
|
|
|
|
|
|
|
/// <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);
|
2020-10-31 22:27:18 +00:00
|
|
|
}
|