Gfsr Engine Structure
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
public struct GfsrEngine : IScalarEngine<uint>,
IRandomEngine, IStateful- Implements
- IRandomEngine, IScalarEngine<UInt32>, IStateful
Remarks
The GFSR engine is a linear feedback shift register-based pseudo-random number generator using a fourth-order generalized feedback shift register algorithm. It features a very large state array and an exceptionally long period.
Algorithm Details:
- State size: 524288 bits (16384 × 32-bit words + index)
- Period: 29689 - 1
- Taps: Four-tap LFSR at positions 471, 1586, 6988, and 9689
- Performance: Very fast generation after initialization
Characteristics:
GFSR generators are extremely simple and fast once initialized. The output at each step is computed by XORing four previous values at fixed lag positions. However, they have several drawbacks:
- Large state: 64 KB of state memory
- Slow initialization: Filling the large state array takes significant time
- Poor quality: Fails many modern statistical tests (BigCrush)
- Linear: Being a linear generator, it's unsuitable for cryptography
Historical Context:
GFSR was popular in the 1990s for scientific computing due to its simplicity and speed. However, it has been superseded by better algorithms like the Mersenne Twister and modern generators like Xoshiro/Xoroshiro.
Modern Alternatives:
For new applications, strongly prefer modern generators like Xoshiro256StarStarEngine or Pcg64Engine which offer far better statistical quality, much smaller state, and similar or better performance.
Note: This generator is provided for legacy compatibility and historical reproducibility only. It does not support jumping or fast-forward operations.
Reference: Robert M. Ziff, "Four-tap shift-register-sequence random-number generators." Computers in Physics 12(4), Jul/Aug 1998, pp 385-392.
Example
var engine = new GfsrEngine();
engine.Seed(SeedSequences.SplitMix64(12345));
uint value = engine.Next();
uint[] values = new uint[100];
engine.Fill(values);
// Save and restore state
byte[] state = new byte[engine.StateSize];
engine.SaveState(state);
engine.LoadState(state);Constructors
| Gfsr | Initializes a new GFSR engine. |
Properties
| Bits | Gets the native word size in bits. |
| Name | Gets a human-readable name for this engine. |
| State | Gets the number of bytes required to save/load this engine's state. |
Methods
| Advance | Advances the engine state by one transition step. |
| Equals | Indicates whether this instance and a specified object are equal. (Inherited from ValueType) |
| Fill | Fills the destination span with successive native words from the engine's stream. |
| Get | Returns the hash code for this instance. (Inherited from ValueType) |
| 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 | Advances the engine by one step and returns the native word produced for that step. |
| Output | Returns the native word produced by applying the output mapping function to the current engine state, without mutating that state. |
| Save | Saves the engine's state to the destination span in a stable little-endian format. |
| Seed( | Directly sets the GFSR state array. |
| Seed( | Initializes the engine state from a seed sequence. |
| ToString | Returns the fully qualified type name of this instance. (Inherited from ValueType) |