Numerics. NET. Random. Generators Namespace
Provides Layer 2 generator structs that adapt Layer 1 engines into a uniform primitive RNG API.
Remarks
Layer 2 generators are generic structs that wrap Layer 1 engine types and implement the IRandomGenerator interface, providing three primitive operations:
- NextUInt32(): Generates a 32-bit unsigned integer.
- NextUInt64(): Generates a 64-bit unsigned integer.
- NextBytes(Span<Byte>): Fills a span with random bytes in little-endian order.
Generator Types:
- ScalarGenerator32<TEngine>: Adapts 32-bit scalar engines (e.g., Pcg32).
- ScalarGenerator64<TEngine>: Adapts 64-bit scalar engines with uint caching (e.g., Pcg64).
- BlockGenerator32<TEngine>: Adapts 32-bit block engines (e.g., Mersenne Twister).
- BlockGenerator64<TEngine>: Adapts 64-bit block engines with uint caching (e.g., MT64).
- CounterBasedGenerator32<TEngine>: Adapts 32-bit counter-based engines (e.g., Philox-4x32).
- CounterBasedGenerator64<TEngine>: Adapts 64-bit counter-based engines with uint caching (e.g., Philox-4x64).
Design Principles:
- All generators are structs for performance and should be passed by reference in hot paths.
- 64-bit generators cache the high 32 bits when NextUInt32() is called.
- All byte sequences are little-endian for cross-platform portability.
- Counter-based generators guarantee the underlying engine is always in a consistent state when producing output.
Structures
| Block | A generator struct that adapts a 32-bit non-counter block engine into the IRandomGenerator interface. |
| Block | A generator struct that adapts a 64-bit non-counter block engine into the IRandomGenerator interface, with uint caching for efficient 32-bit word generation. |
| Counter | A generator struct that adapts a 32-bit counter-based engine into the IRandomGenerator interface. |
| Counter | A generator struct that adapts a 64-bit counter-based engine into the IRandomGenerator interface, with uint caching for efficient 32-bit word generation. |
| Scalar | A generator struct that adapts a 32-bit scalar engine into the IRandomGenerator interface. |
| Scalar | A generator struct that adapts a 64-bit scalar engine into the IRandomGenerator interface, with uint caching for efficient 32-bit word generation. |