IStateful Interface
Represents an object that supports portable state persistence.
Definition
Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
public interface IStatefulRemarks
All random number generator engines are stateful and must support saving and loading their complete state in a stable, portable format that works across all architectures (x86, x64, ARM, ARM64), operating systems, and .NET runtimes.
State Format Requirements:
- Little-endian byte order: State bytes are always interpreted as little-endian regardless of the host architecture's native endianness.
- Stable across versions: The state format must remain stable across library versions to ensure long-term persistence and reproducibility.
- Architecture-independent: The same byte sequence must produce the same generator state on all platforms.
- Complete state capture: All information required to reproduce subsequent outputs must be included in the saved state.
Usage Pattern:
To save and restore generator state:
// Save state
var rng = new Pcg64Engine();
byte[] stateBytes = new byte[rng.StateSize];
rng.SaveState(stateBytes);
// Load state (same or different process/machine)
var rng2 = new Pcg64Engine();
rng2.LoadState(stateBytes);
// rng2 now produces the same sequence as rng would haveProperties
| State | Gets the number of bytes required to save/load this engine's state. |
Methods
| Load | Loads the engine's state from the source span in a stable little-endian format. |
| Save | Saves the engine's state to the destination span in a stable little-endian format. |