Class RNG
Random Number Generator.
public class RNG : UnmanagedObject, IDisposable
- Inheritance
-
RNG
- Implements
- Inherited Members
Constructors
RNG()
Create a Random Number Generator.
public RNG()
RNG(ulong)
Create a Random Number Generator using a seed.
public RNG(ulong state)
Parameters
state
ulong64-bit value used to initialize the RNG
Methods
DisposeObject()
Release the unmanaged resources
protected override void DisposeObject()
Fill(IInputOutputArray, DistType, IInputArray, IInputArray, bool)
Fills arrays with random numbers.
public void Fill(IInputOutputArray mat, RNG.DistType distType, IInputArray a, IInputArray b, bool saturateRange = false)
Parameters
mat
IInputOutputArray2D or N-dimensional matrix; currently matrices with more than 4 channels are not supported by the methods, use Mat::reshape as a possible workaround.
distType
RNG.DistTypedistribution type
a
IInputArrayFirst distribution parameter; in case of the uniform distribution, this is an inclusive lower boundary, in case of the normal distribution, this is a mean value.
b
IInputArraySecond distribution parameter; in case of the uniform distribution, this is a non-inclusive upper boundary, in case of the normal distribution, this is a standard deviation (diagonal of the standard deviation matrix or the full standard deviation matrix).
saturateRange
boolPre-saturation flag; for uniform distribution only; if true, the method will first convert a and b to the acceptable value range (according to the mat datatype) and then will generate uniformly distributed random numbers within the range [saturate(a), saturate(b)), if saturateRange=false, the method will generate uniformly distributed random numbers in the original range [a, b) and then will saturate them
Fill(IInputOutputArray, DistType, MCvScalar, MCvScalar, bool)
Fills arrays with random numbers.
public void Fill(IInputOutputArray mat, RNG.DistType distType, MCvScalar a, MCvScalar b, bool saturateRange = false)
Parameters
mat
IInputOutputArray2D or N-dimensional matrix; currently matrices with more than 4 channels are not supported by the methods, use Mat::reshape as a possible workaround.
distType
RNG.DistTypedistribution type
a
MCvScalarFirst distribution parameter; in case of the uniform distribution, this is an inclusive lower boundary, in case of the normal distribution, this is a mean value.
b
MCvScalarSecond distribution parameter; in case of the uniform distribution, this is a non-inclusive upper boundary, in case of the normal distribution, this is a standard deviation (diagonal of the standard deviation matrix or the full standard deviation matrix).
saturateRange
boolPre-saturation flag; for uniform distribution only; if true, the method will first convert a and b to the acceptable value range (according to the mat datatype) and then will generate uniformly distributed random numbers within the range [saturate(a), saturate(b)), if saturateRange=false, the method will generate uniformly distributed random numbers in the original range [a, b) and then will saturate them
Gaussian(double)
Returns the next random number sampled from the Gaussian distribution.
public double Gaussian(double sigma)
Parameters
sigma
doublestandard deviation of the distribution.
Returns
- double
Returns the next random number from the Gaussian distribution N(0,sigma) . That is, the mean value of the returned random numbers is zero and the standard deviation is the specified sigma .
Next()
The method updates the state using the MWC algorithm and returns the next 32-bit random number.
public uint Next()
Returns
- uint
The next 32-bit random number
Uniform(double, double)
Returns uniformly distributed random double number from [a,b) range
public double Uniform(double a, double b)
Parameters
a
doubleLower inclusive boundary of the returned random number.
b
doubleUpper non-inclusive boundary of the returned random number.
Returns
- double
Uniformly distributed random double number from [a,b) range
Uniform(int, int)
Returns uniformly distributed integer random number from [a,b) range
public int Uniform(int a, int b)
Parameters
a
intLower inclusive boundary of the returned random number.
b
intUpper non-inclusive boundary of the returned random number.
Returns
- int
Uniformly distributed integer random number from [a,b) range
Uniform(float, float)
Returns uniformly distributed random float number from [a,b) range
public float Uniform(float a, float b)
Parameters
a
floatLower inclusive boundary of the returned random number.
b
floatUpper non-inclusive boundary of the returned random number.
Returns
- float
Uniformly distributed random float number from [a,b) range