FastRng/FastRng/IRandom.cs

46 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System;
using System.Numerics;
2020-10-31 22:27:18 +00:00
using System.Threading;
namespace FastRng;
/// <summary>
/// Interface for random number generators.
/// </summary>
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>
/// 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>
/// <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);
2020-10-31 22:27:18 +00:00
}