Xoshiro128Plus Class

Represents a pseudo-random number generator based on the Xoshiro128+ algorithm.

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public sealed class Xoshiro128Plus : RandomSource<ScalarGenerator32<Xoshiro128PlusEngine>>, 
	IRandomSourceFactory<Xoshiro128Plus>, IAdvanceable, IJumpable
Inheritance
Object  →  RandomSource<ScalarGenerator32<Xoshiro128PlusEngine>>  →  Xoshiro128Plus
Implements
IAdvanceable, IJumpable, IRandomSourceFactory<Xoshiro128Plus>

Remarks

Use the Xoshiro128Plus class to represent a pseudo-random number generator that uses the Xoshiro128+ algorithm by David Blackman and Sebastiano Vigna.

This generator has a period of 2128 - 1 and is optimized for high-performance floating-point generation. The "+" scrambler is fast but has low linear complexity in the low bits.

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

Performance: This generator is one of the fastest 32-bit RNGs available and is particularly well-suited for generating floating-point numbers where only high bits are used.

Use cases:

  • High-performance floating-point generation
  • Applications where only high bits are used (e.g., NextDouble())
  • Parallel computing with jump-ahead capability

Avoid using for:

  • Integer generation (use Xoshiro128StarStar instead)
  • Bit-level operations requiring uniformity in low bits
  • Cryptographic purposes (like all PRNGs in this library)

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

Example

C#
// Good use case: floating-point generation
var rng = new Xoshiro128Plus(123);
double x = rng.NextDouble();
float y = rng.NextSingle();

// Bad use case: integer generation (use Xoshiro128StarStar instead)
// uint n = rng.NextUInt32(); // Low bits have poor quality!

Constructors

Xoshiro128Plus() Initializes a new instance of the Xoshiro128Plus class using OS entropy.
Xoshiro128Plus(RandomOptions) Initializes a new instance of the Xoshiro128Plus class with the specified options.
Xoshiro128Plus(ReadOnlySpan<Byte>) Initializes a new instance of the Xoshiro128Plus class from saved state.
Xoshiro128Plus(Int64, SeedProfile) Initializes a new instance of the Xoshiro128Plus class with the specified seed.
Xoshiro128Plus(ReadOnlySpan<UInt32>, SeedProfile) Initializes a new instance of the Xoshiro128Plus class with the specified seed array.
Xoshiro128Plus(Int64, StreamAddress, SeedProfile) Initializes a new instance of the Xoshiro128Plus class with the specified seed.
Xoshiro128Plus(ReadOnlySpan<UInt32>, StreamAddress, SeedProfile) Initializes a new instance of the Xoshiro128Plus class with the specified seed array.

Properties

BitsPerWord Gets the number of bits per word in the generator's native output.
(Overrides RandomSource<TGenerator>.BitsPerWord)
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 random number generator.
(Overrides RandomSource<TGenerator>.Name)
StateSize 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

Advance Advances the generator state by the specified number of steps.
Copy Creates an exact copy of this generator with the same state.
Create Creates a new Xoshiro128Plus instance from the specified options.
CreateStreamPartition Creates a jump-based stream partition for generating independent RNG streams.
CreateStreamTree Creates a hierarchical stream tree for generating independent RNG streams.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Fill(Span<UInt32>) Fills a span with random 32-bit unsigned integer values.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int32>, Int32) Fills a span with random 32-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int64>, Int64) Fills a span with random 64-bit signed integers less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int32>, Int32, Int32) Fills a span with random 32-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>)
Fill(Span<Int64>, Int64, Int64) Fills a span with random 64-bit signed integers within a specified range.
(Inherited from RandomSource<TGenerator>)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetState Returns the current state of the generator as a byte array.
(Inherited from RandomSource<TGenerator>)
GetTypeGets the Type of the current instance.
(Inherited from Object)
Jumped Returns a new instance of the random number generator that is advanced by a specified number of jumps in the sequence.
LoadState Loads the generator's state from the source span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>)
LongJumped Returns a new instance of the random number generator that is advanced by a specified number of long jumps in the sequence.
Next() Returns a non-negative random integer.
(Inherited from RandomSource<TGenerator>)
Next(Int32) Returns a non-negative random integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
Next(Int32, Int32) Returns a random integer within a specified range.
(Inherited from RandomSource<TGenerator>)
NextBytes(Byte[]) Fills the elements of a specified array of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextBytes(Span<Byte>) Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextBytes(Byte[], Boolean) Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextBytes(Span<Byte>, Boolean) Fills the elements of a specified span of bytes with random numbers.
(Inherited from RandomSource<TGenerator>)
NextDouble Returns a random floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>)
NextInt64() Returns a non-negative random 64-bit integer.
(Inherited from RandomSource<TGenerator>)
NextInt64(Int64) Returns a non-negative random 64-bit integer less than the specified maximum.
(Inherited from RandomSource<TGenerator>)
NextInt64(Int64, Int64) Returns a random 64-bit integer within a specified range.
(Inherited from RandomSource<TGenerator>)
NextSingle Returns a random single-precision floating-point number in the range [0.0, 1.0).
(Inherited from RandomSource<TGenerator>)
NextUInt32 Returns a random 32-bit unsigned integer.
(Inherited from RandomSource<TGenerator>)
NextUInt64 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>)
SaveState Saves the generator's state to the destination span in a stable little-endian format.
(Inherited from RandomSource<TGenerator>)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also