Class Xoroshiro128PlusPlus
- Namespace
- BelNytheraSeiche.TrieDictionary
- Assembly
- BelNytheraSeiche.TrieDictionary.dll
Represents a 64-bit pseudo-random number generator based on the xoroshiro128++ algorithm.
public class Xoroshiro128PlusPlus : ICloneable
- Inheritance
-
Xoroshiro128PlusPlus
- Implements
- Inherited Members
Remarks
This generator is not cryptographically secure.
Constructors
Xoroshiro128PlusPlus()
Initializes a new instance of the Xoroshiro128PlusPlus class, using a unique seed value derived from a new GUID.
public Xoroshiro128PlusPlus()
Xoroshiro128PlusPlus(Xoroshiro128PlusPlus)
Initializes a new instance of the Xoroshiro128PlusPlus class by copying the state from another instance.
public Xoroshiro128PlusPlus(Xoroshiro128PlusPlus obj)
Parameters
obj
Xoroshiro128PlusPlusThe Xoroshiro128PlusPlus instance to copy the state from.
Remarks
This constructor is primarily intended for replicating the state of the generator for parallel processing scenarios. After creating a copy, call the Jump() method on one of the instances to ensure that each generator produces a non-overlapping sequence of random numbers.
Exceptions
- ArgumentNullException
obj
is null.
Xoroshiro128PlusPlus(ulong)
Initializes a new instance of the Xoroshiro128PlusPlus class, using the specified seed value.
public Xoroshiro128PlusPlus(ulong seed)
Parameters
seed
ulongA number used to calculate a starting value for the pseudo-random number sequence.
Methods
Clone()
Creates a new object that is a shallow copy of the current instance.
public object Clone()
Returns
- object
A new object that is a shallow copy of this instance.
Remarks
This constructor is primarily intended for replicating the state of the generator for parallel processing scenarios. After creating a copy, call the Jump() method on one of the instances to ensure that each generator produces a non-overlapping sequence of random numbers.
Jump()
Advances the state of the generator by 2^64 steps.
public void Jump()
Remarks
This is equivalent to generating 2^64 random numbers and discarding them, but it is executed much faster. It is useful for creating non-overlapping subsequences for parallel random number generation.
Next()
Returns a non-negative random integer.
public int Next()
Returns
Next(int)
Returns a non-negative random integer that is less than the specified maximum.
public int Next(int maxValue)
Parameters
maxValue
intThe exclusive upper bound of the random number to be generated.
maxValue
must be greater than or equal to 0.
Returns
- int
A 32-bit signed integer that is greater than or equal to 0, and less than
maxValue
.
Remarks
If maxValue
is 0, this method will always return 0.
Next(int, int)
Returns a random integer that is within a specified range.
public int Next(int minValue, int maxValue)
Parameters
minValue
intThe inclusive lower bound of the random number returned.
maxValue
intThe exclusive upper bound of the random number returned.
maxValue
must be greater than or equal tominValue
.
Returns
- int
A 32-bit signed integer greater than or equal to
minValue
and less thanmaxValue
.
Remarks
If minValue
equals maxValue
, this method returns minValue
.
Exceptions
- ArgumentOutOfRangeException
minValue
is greater thanmaxValue
.
NextBytes(Span<byte>)
Fills the elements of a specified span of bytes with random numbers.
public void NextBytes(Span<byte> buffer)
Parameters
NextDouble()
Returns a random double-precision floating-point number that is greater than or equal to 0.0, and less than 1.0.
public double NextDouble()
Returns
- double
A double-precision floating-point number that is greater than or equal to 0.0 and less than 1.0.
NextInt64()
Returns a non-negative random 64-bit integer.
public long NextInt64()
Returns
NextInt64(long)
Returns a non-negative random 64-bit integer that is less than the specified maximum.
public long NextInt64(long maxValue)
Parameters
maxValue
longThe exclusive upper bound of the random number to be generated.
maxValue
must be greater than or equal to 0.
Returns
- long
A 64-bit signed integer that is greater than or equal to 0, and less than
maxValue
.
Remarks
If maxValue
is 0, this method will always return 0.
NextInt64(long, long)
Returns a random 64-bit integer that is within a specified range.
public long NextInt64(long minValue, long maxValue)
Parameters
minValue
longThe inclusive lower bound of the random number returned.
maxValue
longThe exclusive upper bound of the random number returned.
maxValue
must be greater than or equal tominValue
.
Returns
- long
A 64-bit signed integer greater than or equal to
minValue
and less thanmaxValue
.
Remarks
If minValue
equals maxValue
, this method returns minValue
.
Exceptions
- ArgumentOutOfRangeException
minValue
is greater thanmaxValue
.
NextSingle()
Returns a random single-precision floating-point number that is greater than or equal to 0.0, and less than 1.0.
public float NextSingle()
Returns
- float
A single-precision floating-point number that is greater than or equal to 0.0f and less than 1.0f.
Shuffle<T>(IList<T>)
Randomizes the order of the elements in a list.
public void Shuffle<T>(IList<T> values)
Parameters
values
IList<T>The list whose elements to shuffle.
Type Parameters
T
The type of the elements of the list.
Remarks
This method uses the Fisher-Yates shuffle algorithm.
Exceptions
- ArgumentNullException
values
is null.
Shuffle<T>(Span<T>)
Randomizes the order of the elements in a span.
public void Shuffle<T>(Span<T> values)
Parameters
values
Span<T>The span whose elements to shuffle.
Type Parameters
T
The type of the elements of the span.
Remarks
This method uses the Fisher-Yates shuffle algorithm.