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
stateulong64-bit value used to initialize the RNG.
Properties
State
public ulong State { get; set; }
Property Value
Methods
Equals(RNG)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(RNG other)
Parameters
otherRNGAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
matInputOutputArray2D or N-dimensional matrix; currently matrices with more than 4 channels are not supported by the methods, use Mat::reshape as a possible workaround.
distTypeDistributionTypedistribution type, RNG::UNIFORM or RNG::NORMAL.
aInputArrayfirst 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.
bInputArraysecond 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).
saturateRangeboolpre-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
sigmadoublestandard deviation of the distribution.
Returns
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
Run()
public uint Run()
Returns
Run(uint)
returns a random integer sampled uniformly from [0, N).
public uint Run(uint n)
Parameters
nuint
Returns
ToByte()
(byte)RNG.next()
public byte ToByte()
Returns
ToDouble()
returns a next random value as double (System.Double)
public double ToDouble()
Returns
ToInt16()
(short)RNG.next()
public short ToInt16()
Returns
ToInt32()
(int)RNG.next()
public int ToInt32()
Returns
ToSByte()
(sbyte)RNG.next()
public sbyte ToSByte()
Returns
ToSingle()
returns a next random value as float (System.Single)
public float ToSingle()
Returns
ToUInt16()
(ushort)RNG.next()
public ushort ToUInt16()
Returns
ToUInt32()
(uint)RNG.next()
public uint ToUInt32()
Returns
Uniform(double, double)
returns uniformly distributed double-precision floating-point random number from [a,b) range
public double Uniform(double a, double b)
Parameters
Returns
Uniform(int, int)
returns uniformly distributed integer random number from [a,b) range
public int Uniform(int a, int b)
Parameters
Returns
Uniform(float, float)
returns uniformly distributed floating-point random number from [a,b) range
public float Uniform(float a, float b)
Parameters
Returns
Operators
operator ==(RNG, RNG)
public static bool operator ==(RNG left, RNG right)
Parameters
Returns
explicit operator byte(RNG)
(byte)RNG.next()
public static explicit operator byte(RNG self)
Parameters
selfRNG
Returns
explicit operator double(RNG)
returns a next random value as double (System.Double)
public static explicit operator double(RNG self)
Parameters
selfRNG
Returns
explicit operator short(RNG)
(short)RNG.next()
public static explicit operator short(RNG self)
Parameters
selfRNG
Returns
explicit operator int(RNG)
(int)RNG.next()
public static explicit operator int(RNG self)
Parameters
selfRNG
Returns
explicit operator sbyte(RNG)
(sbyte)RNG.next()
public static explicit operator sbyte(RNG self)
Parameters
selfRNG
Returns
explicit operator float(RNG)
returns a next random value as float (System.Single)
public static explicit operator float(RNG self)
Parameters
selfRNG
Returns
explicit operator ushort(RNG)
(ushort)RNG.next()
public static explicit operator ushort(RNG self)
Parameters
selfRNG
Returns
explicit operator uint(RNG)
(uint)RNG.next()
public static explicit operator uint(RNG self)
Parameters
selfRNG
Returns
operator !=(RNG, RNG)
public static bool operator !=(RNG left, RNG right)