Counter Based Generator 32<TEngine> Structure
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
public struct CounterBasedGenerator32<TEngine> : IBlockRandomGenerator,
IRandomGenerator, IStateful, ICounterBased<uint>, IAdvanceable
where TEngine : struct, new(), ICounterBased<uint>, IBlockEngine<uint>, IStateful
- Implements
- ICounterBased<UInt32>, IAdvanceable, IBlockRandomGenerator, IRandomGenerator, IStateful
Type Parameters
- TEngine
- The engine type, which must be a struct implementing ICounterBased<T> and IBlockEngine<T> for UInt32, and IStateful.
Remarks
CounterBasedGenerator32<TEngine> wraps a counter-based engine (e.g., Philox-4x32) and provides:
- NextUInt32(): Returns the next word from the current block via engine.Output(index).
- NextUInt64(): Composes two 32-bit words in little-endian order.
- NextBytes(Span<Byte>): Writes bytes via NextUInt32() in 4-byte chunks (little-endian), with tail handling.
Refill Policy (Advance-on-Empty, Consistent-by-Contract):
When the block is exhausted (_index == BlockLength), the generator calls AdvanceBlock() which advances the counter by one block and establishes a consistent state for the new block coordinates. The generator then resets _index = 0. This ensures the engine is always in a consistent state when Output(Int32) is called.
Consistency Guarantee:
All generator methods guarantee that whenever they produce output from the engine, the engine is in a consistent state. AdvanceBlock(UInt64) is guaranteed by Layer 1 to leave the engine consistent, so Layer 2 does not need to call GenerateBlock() in the normal refill path.
State Persistence:
Layer 2 state includes engine state (including any engine-owned cached block material) plus the cursor index (4 bytes LE).
Constructors
| Counter | Initializes a new instance of the CounterBasedGenerator32<TEngine> struct with the specified engine. |
Properties
| Block | Gets the number of words per block produced by this generator. |
| Counter | Gets the number of words in the engine counter. |
| Key | Gets the number of words in the engine key. |
| State | Gets the number of bytes required to save/load this engine's state. |
Methods
| Advance | Advances the RNG state by the specified number of outputs. |
| Advance | Advances the counter by the specified number of blocks. |
| Equals | Indicates whether this instance and a specified object are equal. (Inherited from ValueType) |
| Fill( | Fills the specified span with random double-precision floating-point numbers. |
| Fill( | Fills the specified span with random single-precision floating-point numbers. |
| Fill( | Fills the specified span with random 32-bit unsigned integers. |
| Fill( | Fills the specified span with random 64-bit unsigned integers. |
| Get | Copies the current counter into the provided destination span. |
| Get | Returns the hash code for this instance. (Inherited from ValueType) |
| Get | Copies the current key into the provided destination span. |
| Get | Gets the Type of the current instance. (Inherited from Object) |
| Load | Loads the engine's state from the source span in a stable little-endian format. |
| Next | Fills the specified span with random bytes in little-endian order. |
| Next | Generates the next double-precision floating-point number. |
| Next | Generates the next single-precision floating-point number. |
| Next | Generates the next 32-bit unsigned integer. |
| Next | Generates the next 64-bit unsigned integer. |
| Reset | Resets the counter to all zeros. |
| Save | Saves the engine's state to the destination span in a stable little-endian format. |
| Set | Sets the counter to the specified value. |
| Set | Sets the key to the specified value. |
| ToString | Returns the fully qualified type name of this instance. (Inherited from ValueType) |