Class XorShift128Generator
Represents a xorshift pseudo-random number generator with period 2^128-1.
Inherited Members
Namespace: Experior.Core.Mathematics.Statistics.Generators.Continuous
Assembly: Experior.Core.dll
Syntax
public class XorShift128Generator : Generator
Remarks
The XorShift128Generator type bases upon the implementation presented in the CP article "A fast equivalent for System.Random" and the theoretical background on xorshift random number generators published by George Marsaglia in this paper "Xorshift RNGs".
Constructors
XorShift128Generator()
Initializes a new instance of the XorShift128Generator class, using a time-dependent default seed value.
Declaration
public XorShift128Generator()
XorShift128Generator(Int32)
Initializes a new instance of the XorShift128Generator class, using the specified seed value.
Declaration
public XorShift128Generator(int seed)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | seed | A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used. |
XorShift128Generator(UInt32)
Initializes a new instance of the XorShift128Generator class, using the specified seed value.
Declaration
[CLSCompliant(false)]
public XorShift128Generator(uint seed)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | seed | An unsigned number used to calculate a starting value for the pseudo-random number sequence. |
Properties
CanReset
Gets a value indicating whether the XorShift128Generator can be reset, so that it produces the same pseudo-random number sequence again.
Declaration
public override bool CanReset { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Overrides
Methods
Next()
Returns a nonnegative random number less than System.Int32.MaxValue.
Declaration
public override int Next()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to 0, and less than System.Int32.MaxValue; that is,
the range of return values includes 0 but not |
Overrides
Next(Int32)
Returns a nonnegative random number less than the specified maximum.
Declaration
public override int Next(int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to 0, and less than |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
Next(Int32, Int32)
Returns a random number within the specified range.
Declaration
public override int Next(int minValue, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | minValue | The inclusive lower bound of the random number to be generated. |
System.Int32 | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
NextBoolean()
Returns a random Boolean value.
Declaration
public override bool NextBoolean()
Returns
Type | Description |
---|---|
System.Boolean | A System.Boolean value. |
Overrides
Remarks
Buffers 31 random bits for future calls, so the random number generator is only invoked once in every 31 calls.
NextBytes(Byte[])
Fills the elements of a specified array of bytes with random numbers.
Declaration
public override void NextBytes(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | An array of bytes to contain random numbers. |
Overrides
Remarks
Each element of the array of bytes is set to a random number greater than or equal to 0, and less than or equal to System.Byte.MaxValue.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
NextDouble()
Returns a nonnegative floating point random number less than 1.0.
Declaration
public override double NextDouble()
Returns
Type | Description |
---|---|
System.Double | A double-precision floating point number greater than or equal to 0.0, and less than 1.0; that is, the range of return values includes 0.0 but not 1.0. |
Overrides
NextDouble(Double)
Returns a nonnegative floating point random number less than the specified maximum.
Declaration
public override double NextDouble(double maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Double | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Double | A double-precision floating point number greater than or equal to 0.0, and less than |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException |
NextDouble(Double, Double)
Returns a floating point random number within the specified range.
Declaration
public override double NextDouble(double minValue, double maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Double | minValue | The inclusive lower bound of the random number to be generated.
The range between |
System.Double | maxValue | The exclusive upper bound of the random number to be generated.
|
Returns
Type | Description |
---|---|
System.Double | A double-precision floating point number greater than or equal to |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | |
System.ArgumentException |
NextInclusiveMaxValue()
Returns a nonnegative random number less than or equal to System.Int32.MaxValue.
Declaration
public int NextInclusiveMaxValue()
Returns
Type | Description |
---|---|
System.Int32 | A 32-bit signed integer greater than or equal to 0, and less than or equal to System.Int32.MaxValue;
that is, the range of return values includes 0 and |
NextUInt()
Returns an unsigned random number.
Declaration
public uint NextUInt()
Returns
Type | Description |
---|---|
System.UInt32 | A 32-bit unsigned integer greater than or equal to System.UInt32.MinValue and
less than or equal to |
Reset()
Resets the XorShift128Generator, so that it produces the same pseudo-random number sequence again.
Declaration
public override bool Reset()
Returns
Type | Description |
---|---|
System.Boolean | true. |