Updated documentation

This commit is contained in:
Thorsten Sommer 2023-07-10 19:36:31 +02:00
parent 36c94be6d0
commit df003facfd
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 10 additions and 11 deletions

View File

@ -12,8 +12,7 @@ namespace FastRng;
/// </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/>
/// Unlike Math.NET, MultiThreadedRng is multi-threaded. Consumers can use a token to cancel e.g. timeout an operation.<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
@ -23,7 +22,7 @@ namespace FastRng;
/// 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,
/// Please notice: When using the debug environment, MultiThreadedRng might uses a smaller buffer size. Please ensure,
/// that the production environment uses a release build, though.
/// </remarks>
public sealed class MultiThreadedRng<TNum> : IRandom<TNum>, IDisposable where TNum : IFloatingPointIeee754<TNum>, IAdditionOperators<TNum, TNum, TNum>

View File

@ -2,13 +2,13 @@
FastRng is a multi-threaded pseudo-random number generator. Besides the generation of uniformly distributed random numbers, there are several other distributions to choose from. For performance reasons the parameters of the distributions are not user-definable. For some distributions, therefore, different parameter variations are available. If a different combination is desired, a separate class can be created.
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.
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. Consumers can use a token to cancel e.g. timeout an operation.
FastRng (class `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.
The class `MultiThreadedRng` 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.
Please notice: When using the debug environment, MultiThreadedRng uses a smaller buffer size. Please ensure, that the production environment uses a release build, though.
Please notice: When using the debug environment, MultiThreadedRng might uses a smaller buffer size. Please ensure, that the production environment uses a release build, though.
## Usage
Example code:
@ -19,19 +19,19 @@ using FastRng.Float.Distributions;
[...]
using var rng = new MultiThreadedRng();
var dist = new ChiSquareK1(rng);
using var rng = new MultiThreadedRng<float>();
var dist = new ChiSquareK1<float>(rng);
var value1 = await dist.NextNumber();
var value2 = await dist.NextNumber(rangeStart: -1.0f, rangeEnd: 1.0f);
if(await dist.HasDecisionBeenMade(above: 0.8f, below: 0.9f))
var value1 = dist.NextNumber();
var value2 = dist.NextNumber(rangeStart: -1.0f, rangeEnd: 1.0f);
if(dist.HasDecisionBeenMade(above: 0.8f, below: 0.9f))
{
// Decision has been made
}
```
Notes:
- `MultiThreadedRng` and all distributions are available as `float` and `double` variations. Both are supporting `uint` and `ulong` as well.
- `MultiThreadedRng` and all distributions are using generic math types: you might use `float`, `double`, or `Half`.
- `MultiThreadedRng` is `IDisposable`. It is important to call `Dispose`, when the generator is not needed anymore. Otherwise, the supporting background threads are still running.