Class Randomizer
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
Represents a pseudo-random number generator, which is a device that produces a sequence of numbers that meet certain statistical requirements for randomness.
Equivalent of Random.
public sealed class Randomizer : ICloneable
- Inheritance
-
Randomizer
- Implements
- Inherited Members
- Extension Methods
Remarks
Copied and modified from https://referencesource.microsoft.com/#mscorlib/system/random.cs
Constructors
Randomizer()
Initializes a new instance of the Randomizer class, using a time-dependent default seed value.
public Randomizer()
Randomizer(int)
Initializes a new instance of the Random class, using the specified seed value.
public Randomizer(int Seed)
Parameters
SeedintA 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.
Methods
Clone()
Creates a new object that is a copy of the current instance.
public Randomizer Clone()
Returns
- Randomizer
A new object that is a copy of this instance.
Deserialize(byte[])
public static Randomizer Deserialize(byte[] bytes)
Parameters
bytesbyte[]
Returns
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
maxValueintThe exclusive upper bound of the random number to be generated.
maxValuemust 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; that is, the range of return values ordinarily includes 0 but notmaxValue. However, ifmaxValueequals 0,maxValueis returned.
Exceptions
- ArgumentOutOfRangeException
maxValueis less than 0.
Next(int, int)
Returns a random integer that is within a specified range.
public int Next(int minValue, int maxValue)
Parameters
minValueintThe inclusive lower bound of the random number returned.
maxValueintThe exclusive upper bound of the random number returned.
maxValuemust be greater than or equal tominValue.
Returns
- int
A 32-bit signed integer greater than or equal to
minValueand less thanmaxValue; that is, the range of return values includesminValuebut notmaxValue. IfminValueequalsmaxValue,minValueis returned.
Exceptions
- ArgumentOutOfRangeException
minValueis greater thanmaxValue.
NextBytes(byte[])
Fills the elements of a specified array of bytes with random numbers.
public void NextBytes(byte[] buffer)
Parameters
bufferbyte[]An array of bytes to contain random numbers.
Exceptions
- ArgumentNullException
bufferis null.
NextDouble()
Returns a random 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.
NextLong()
Returns a non-negative random integer that is less than the specified maximum.
public long NextLong()
Returns
- long
A 32-bit signed integer that is greater than or equal to 0, and less than
maxValue; that is, the range of return values ordinarily includes 0 but notmaxValue. However, ifmaxValueequals 0,maxValueis returned.
Exceptions
- ArgumentOutOfRangeException
maxValueis less than 0.
NextLong(long)
Returns a non-negative random integer that is less than the specified maximum.
public long NextLong(long maxValue)
Parameters
maxValuelongThe exclusive upper bound of the random number to be generated.
maxValuemust be greater than or equal to 0.
Returns
- long
A 32-bit signed integer that is greater than or equal to 0, and less than
maxValue; that is, the range of return values ordinarily includes 0 but notmaxValue. However, ifmaxValueequals 0,maxValueis returned.
Exceptions
- ArgumentOutOfRangeException
maxValueis less than 0.
NextLong(long, long)
Returns a random integer that is within a specified range.
public long NextLong(long minValue, long maxValue)
Parameters
minValuelongThe inclusive lower bound of the random number returned.
maxValuelongThe exclusive upper bound of the random number returned.
maxValuemust be greater than or equal tominValue.
Returns
- long
A 32-bit signed integer greater than or equal to
minValueand less thanmaxValue; that is, the range of return values includesminValuebut notmaxValue. IfminValueequalsmaxValue,minValueis returned.
Exceptions
- ArgumentOutOfRangeException
minValueis greater thanmaxValue.
Sample()
Returns a random floating-point number between 0.0 and 1.0.
protected double Sample()
Returns
- double
A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0.
Serialize()
public byte[] Serialize()
Returns
- byte[]