GFSR Class
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
public sealed class GFSR : RandomSource<ScalarGenerator32<GfsrEngine>>,
IRandomSourceFactory<GFSR>- Inheritance
- Object → RandomSource<ScalarGenerator32<GfsrEngine>> → GFSR
- Implements
- IRandomSourceFactory<GFSR>
Remarks
Use the GFSR class to represent a pseudo-random number generator that uses a fourth-order generalized feedback shift register algorithm.
This generator has a very long period of 29689 - 1. Thanks to its simplicity, generation is very fast. However, initialization is slow due to the large state size (64 KB).
GFSR generators are linear and fail many modern statistical tests. They are provided primarily for legacy compatibility and historical reproducibility.
For new applications, strongly consider using modern generators like Pcg64, Xoshiro256StarStar, or Xoshiro256Plus which offer far better statistical quality, much smaller state, and similar or better performance.
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 rng = new Gsfr(12345);
uint value = rng.NextUInt32();
double x = rng.NextDouble();Constructors
| GFS | Initializes a new instance of the Gsfr class using OS entropy. |
| GFS | Initializes a new instance of the Gsfr class with the specified seed array. |
| GFS | Initializes a new instance of the Gsfr class with the specified options. |
| GFS | Initializes a new instance of the Gsfr class from saved state. |
| GFS | Initializes a new instance of the Gsfr class with the specified seed. |
| GFS | Initializes a new instance of the Gsfr class with the specified seed array. |
| GFS | Initializes a new instance of the Gsfr class with the specified seed. |
| GFS | Initializes a new instance of the Gsfr class with the specified seed array. |
Properties
| Bits |
Gets the number of bits per word in the generator's native output.
(Overrides RandomSource<TGenerator>.BitsPerWord) |
| Name |
Gets a human-readable name for this random number generator.
(Overrides RandomSource<TGenerator>.Name) |
| State |
Gets the number of bytes required to save/load this generator's state.
(Inherited from RandomSource<TGenerator>) |
| Uncached |
Gets an uncached facade for this random number generator.
(Inherited from RandomSource<TGenerator>) |
Methods
| Copy | Returns a deep copy of this RNG. |
| Create | Creates a new Gsfr instance from the specified options. |
| Create | Creates a hierarchical stream tree for generating independent RNG streams. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Fill( |
Fills a span with random 32-bit unsigned integer values.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 32-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 64-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 32-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Fill( |
Fills a span with random 64-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Get | Serves as the default hash function. (Inherited from Object) |
| Get |
Returns the current state of the generator as a byte array.
(Inherited from RandomSource<TGenerator>) |
| Get | Gets the Type of the current instance. (Inherited from Object) |
| Load |
Loads the generator's state from the source span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>) |
| Next() |
Returns a non-negative random integer.
(Inherited from RandomSource<TGenerator>) |
| Next( |
Returns a non-negative random integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Next( |
Returns a random integer within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified array of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a non-negative random 64-bit integer.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a non-negative random 64-bit integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random 64-bit integer within a specified range.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random single-precision floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random 32-bit unsigned integer.
(Inherited from RandomSource<TGenerator>) |
| Next |
Returns a random 64-bit unsigned integer.
(Inherited from RandomSource<TGenerator>) |
| Reinitialize |
Reinitializes this random number generator using the specified initialization options.
(Inherited from RandomSource<TGenerator>) |
| Save |
Saves the generator's state to the destination span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |