Show / Hide Table of Contents

Struct RNG

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

Implements
IEquatable<RNG>
Inherited Members
System.ValueType.ToString()
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public struct RNG
Remarks

operations.hpp

Constructors

| Improve this Doc View Source

RNG(UInt64)

Constructor

Declaration
public RNG(ulong state = 4294967295UL)
Parameters
Type Name Description
System.UInt64 state

64-bit value used to initialize the RNG.

Properties

| Improve this Doc View Source

State

Declaration
public ulong State { get; set; }
Property Value
Type Description
System.UInt64

Methods

| Improve this Doc View Source

Equals(RNG)

Declaration
public bool Equals(RNG other)
Parameters
Type Name Description
RNG other
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Equals(Object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean
Overrides
System.ValueType.Equals(System.Object)
| Improve this Doc View Source

Fill(InputOutputArray, DistributionType, InputArray, InputArray, Boolean)

Fills arrays with random numbers.

Declaration
public void Fill(InputOutputArray mat, DistributionType distType, InputArray a, InputArray b, bool saturateRange = false)
Parameters
Type Name Description
InputOutputArray mat

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.

DistributionType distType

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

InputArray a

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.

InputArray b

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).

System.Boolean saturateRange

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).

| Improve this Doc View Source

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.

Declaration
public double Gaussian(double sigma)
Parameters
Type Name Description
System.Double sigma

standard deviation of the distribution.

Returns
Type Description
System.Double
| Improve this Doc View Source

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32
Overrides
System.ValueType.GetHashCode()
| Improve this Doc View Source

Next()

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

Declaration
public uint Next()
Returns
Type Description
System.UInt32
| Improve this Doc View Source

Run()

Declaration
public uint Run()
Returns
Type Description
System.UInt32
| Improve this Doc View Source

Run(UInt32)

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

Declaration
public uint Run(uint n)
Parameters
Type Name Description
System.UInt32 n
Returns
Type Description
System.UInt32
| Improve this Doc View Source

ToByte()

(byte)RNG.next()

Declaration
public byte ToByte()
Returns
Type Description
System.Byte
| Improve this Doc View Source

ToDouble()

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

Declaration
public double ToDouble()
Returns
Type Description
System.Double
| Improve this Doc View Source

ToInt16()

(short)RNG.next()

Declaration
public short ToInt16()
Returns
Type Description
System.Int16
| Improve this Doc View Source

ToInt32()

(int)RNG.next()

Declaration
public int ToInt32()
Returns
Type Description
System.Int32
| Improve this Doc View Source

ToSByte()

(sbyte)RNG.next()

Declaration
public sbyte ToSByte()
Returns
Type Description
System.SByte
| Improve this Doc View Source

ToSingle()

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

Declaration
public float ToSingle()
Returns
Type Description
System.Single
| Improve this Doc View Source

ToUInt16()

(ushort)RNG.next()

Declaration
public ushort ToUInt16()
Returns
Type Description
System.UInt16
| Improve this Doc View Source

ToUInt32()

(uint)RNG.next()

Declaration
public uint ToUInt32()
Returns
Type Description
System.UInt32
| Improve this Doc View Source

Uniform(Double, Double)

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

Declaration
public double Uniform(double a, double b)
Parameters
Type Name Description
System.Double a
System.Double b
Returns
Type Description
System.Double
| Improve this Doc View Source

Uniform(Int32, Int32)

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

Declaration
public int Uniform(int a, int b)
Parameters
Type Name Description
System.Int32 a
System.Int32 b
Returns
Type Description
System.Int32
| Improve this Doc View Source

Uniform(Single, Single)

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

Declaration
public float Uniform(float a, float b)
Parameters
Type Name Description
System.Single a
System.Single b
Returns
Type Description
System.Single

Operators

| Improve this Doc View Source

Equality(RNG, RNG)

Declaration
public static bool operator ==(RNG left, RNG right)
Parameters
Type Name Description
RNG left
RNG right
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Explicit(RNG to Byte)

(byte)RNG.next()

Declaration
public static explicit operator byte (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.Byte
| Improve this Doc View Source

Explicit(RNG to Double)

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

Declaration
public static explicit operator double (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.Double
| Improve this Doc View Source

Explicit(RNG to Int16)

(short)RNG.next()

Declaration
public static explicit operator short (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.Int16
| Improve this Doc View Source

Explicit(RNG to Int32)

(int)RNG.next()

Declaration
public static explicit operator int (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.Int32
| Improve this Doc View Source

Explicit(RNG to SByte)

(sbyte)RNG.next()

Declaration
public static explicit operator sbyte (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.SByte
| Improve this Doc View Source

Explicit(RNG to Single)

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

Declaration
public static explicit operator float (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.Single
| Improve this Doc View Source

Explicit(RNG to UInt16)

(ushort)RNG.next()

Declaration
public static explicit operator ushort (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.UInt16
| Improve this Doc View Source

Explicit(RNG to UInt32)

(uint)RNG.next()

Declaration
public static explicit operator uint (RNG self)
Parameters
Type Name Description
RNG self
Returns
Type Description
System.UInt32
| Improve this Doc View Source

Inequality(RNG, RNG)

Declaration
public static bool operator !=(RNG left, RNG right)
Parameters
Type Name Description
RNG left
RNG right
Returns
Type Description
System.Boolean

Implements

IEquatable<>
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX