Table of Contents

Struct RNG

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Random Number Generator. The class implements RNG using Multiply-with-Carry algorithm.

public struct RNG : IEquatable<RNG>
Implements
Inherited Members

Remarks

operations.hpp

Constructors

RNG(ulong)

Constructor

public RNG(ulong state = 4294967295)

Parameters

state ulong

64-bit value used to initialize the RNG.

Properties

State

public ulong State { get; set; }

Property Value

ulong

Methods

Equals(RNG)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(RNG other)

Parameters

other RNG

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Fill(InputOutputArray, DistributionType, InputArray, InputArray, bool)

Fills arrays with random numbers.

public void Fill(InputOutputArray mat, DistributionType distType, InputArray a, InputArray b, bool saturateRange = false)

Parameters

mat InputOutputArray

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 DistributionType

distribution type, RNG::UNIFORM or RNG::NORMAL.

a InputArray

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 InputArray

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, it means, for example, that theRNG().fill(mat_8u, RNG::UNIFORM, -DBL_MAX, DBL_MAX) will likely produce array mostly filled with 0's and 255's, since the range (0, 255) is significantly smaller than [-DBL_MAX, DBL_MAX).

Gaussian(double)

Returns the next random number sampled from the Gaussian distribution.

The method transforms the state using the MWC algorithm and 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.

public double Gaussian(double sigma)

Parameters

sigma double

standard deviation of the distribution.

Returns

double

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Next()

updates the state and returns the next 32-bit unsigned integer random number

public uint Next()

Returns

uint

Run()

public uint Run()

Returns

uint

Run(uint)

returns a random integer sampled uniformly from [0, N).

public uint Run(uint n)

Parameters

n uint

Returns

uint

ToByte()

(byte)RNG.next()

public byte ToByte()

Returns

byte

ToDouble()

returns a next random value as double (System.Double)

public double ToDouble()

Returns

double

ToInt16()

(short)RNG.next()

public short ToInt16()

Returns

short

ToInt32()

(int)RNG.next()

public int ToInt32()

Returns

int

ToSByte()

(sbyte)RNG.next()

public sbyte ToSByte()

Returns

sbyte

ToSingle()

returns a next random value as float (System.Single)

public float ToSingle()

Returns

float

ToUInt16()

(ushort)RNG.next()

public ushort ToUInt16()

Returns

ushort

ToUInt32()

(uint)RNG.next()

public uint ToUInt32()

Returns

uint

Uniform(double, double)

returns uniformly distributed double-precision floating-point random number from [a,b) range

public double Uniform(double a, double b)

Parameters

a double
b double

Returns

double

Uniform(int, int)

returns uniformly distributed integer random number from [a,b) range

public int Uniform(int a, int b)

Parameters

a int
b int

Returns

int

Uniform(float, float)

returns uniformly distributed floating-point random number from [a,b) range

public float Uniform(float a, float b)

Parameters

a float
b float

Returns

float

Operators

operator ==(RNG, RNG)

public static bool operator ==(RNG left, RNG right)

Parameters

left RNG
right RNG

Returns

bool

explicit operator byte(RNG)

(byte)RNG.next()

public static explicit operator byte(RNG self)

Parameters

self RNG

Returns

byte

explicit operator double(RNG)

returns a next random value as double (System.Double)

public static explicit operator double(RNG self)

Parameters

self RNG

Returns

double

explicit operator short(RNG)

(short)RNG.next()

public static explicit operator short(RNG self)

Parameters

self RNG

Returns

short

explicit operator int(RNG)

(int)RNG.next()

public static explicit operator int(RNG self)

Parameters

self RNG

Returns

int

explicit operator sbyte(RNG)

(sbyte)RNG.next()

public static explicit operator sbyte(RNG self)

Parameters

self RNG

Returns

sbyte

explicit operator float(RNG)

returns a next random value as float (System.Single)

public static explicit operator float(RNG self)

Parameters

self RNG

Returns

float

explicit operator ushort(RNG)

(ushort)RNG.next()

public static explicit operator ushort(RNG self)

Parameters

self RNG

Returns

ushort

explicit operator uint(RNG)

(uint)RNG.next()

public static explicit operator uint(RNG self)

Parameters

self RNG

Returns

uint

operator !=(RNG, RNG)

public static bool operator !=(RNG left, RNG right)

Parameters

left RNG
right RNG

Returns

bool