Xoshiro128PlusEngine Structure

Represents a Xoshiro128+ random number generator engine with 32-bit output.

Definition

Namespace: Numerics.NET.Random.Engines
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public struct Xoshiro128PlusEngine : IScalarEngine<uint>, 
	IRandomEngine, IStateful, IAdvanceable, IJumpable
Inheritance
Object  →  ValueType  →  Xoshiro128PlusEngine
Implements
IRandomEngine, IScalarEngine<UInt32>, IAdvanceable, IJumpable, IStateful

Remarks

The Xoshiro128+ (Xor-Shift-Rotate 128 Plus) engine is a 32-bit random number generator by David Blackman and Sebastiano Vigna. It features a 128-bit state with a period of 2128 - 1 and is optimized for floating-point generation.

Algorithm Details:

  • State size: 128 bits (4 × 32-bit words)
  • Output function: + (Plus) scrambler: s[0] + s[3]
  • Period: 2128 - 1
  • Performance: One of the fastest 32-bit RNGs available

⚠ Warning:

The low bits of this generator have low linear complexity and should NOT be used for integer generation or bit-masking scenarios. Use Xoshiro128** for general-purpose integer generation instead.

Use Cases:

The "+" scrambler is particularly efficient for floating-point generation where only high bits are used. Avoid using for integer generation, bit-level operations, or scenarios requiring uniformity in low bits.

Reference: David Blackman and Sebastiano Vigna. "Scrambled Linear Pseudorandom Number Generators." ACM Trans. Math. Softw. 2021.

See also: https://prng.di.unimi.it/

Example

C#
var engine = new Xoshiro128PlusEngine();
engine.Seed(SeedSequences.SplitMix64(123));

uint value = engine.Next();

uint[] values = new uint[100];
engine.Fill(values);

// Jump for parallel streams
engine.Jump();

Properties

BitsPerWord Gets the native word size in bits.
JumpSize Gets the size category of the primary jump operation.
LongJumpSize Gets the size category of the long jump operation.
Name Gets a human-readable name for this engine.
StateSize Gets the number of bytes required to save/load this engine's state.

Methods

Advance() Advances the engine state by one transition step.
Advance(UInt64) Advances the RNG state by the specified number of outputs.
EqualsIndicates 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.
GetHashCodeReturns the hash code for this instance.
(Inherited from ValueType)
GetTypeGets the Type of the current instance.
(Inherited from Object)
Jump Jumps the RNG forward by the specified number of primary jump strides.
LoadState Loads the engine's state from the source span in a stable little-endian format.
LongJump Jumps the RNG forward by the specified number of long jump strides.
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.
SaveState Saves the engine's state to the destination span in a stable little-endian format.
Seed(SeedSequence) Initializes the engine state from a seed sequence.
Seed(UInt32, UInt32, UInt32, UInt32) Directly sets the four 32-bit state words.
ToStringReturns the fully qualified type name of this instance.
(Inherited from ValueType)

See Also