Table of Contents

Class RNG

Namespace
Emgu.CV
Assembly
Emgu.CV.dll

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 ulong

64-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 IInputOutputArray

2D 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.DistType

distribution type

a IInputArray

First 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 IInputArray

Second 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 bool

Pre-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 IInputOutputArray

2D 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.DistType

distribution type

a MCvScalar

First 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 MCvScalar

Second 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 bool

Pre-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 double

standard 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 double

Lower inclusive boundary of the returned random number.

b double

Upper 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 int

Lower inclusive boundary of the returned random number.

b int

Upper 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 float

Lower inclusive boundary of the returned random number.

b float

Upper non-inclusive boundary of the returned random number.

Returns

float

Uniformly distributed random float number from [a,b) range