Struct opencv::core::RNG

source ·
pub struct RNG { /* private fields */ }
Expand description

Random Number Generator

Random number generator. It encapsulates the state (currently, a 64-bit integer) and has methods to return scalar random values and to fill arrays with random values. Currently it supports uniform and Gaussian (normal) distributions. The generator uses Multiply-With-Carry algorithm, introduced by G. Marsaglia ( http://en.wikipedia.org/wiki/Multiply-with-carry ). Gaussian-distribution random numbers are generated using the Ziggurat algorithm ( http://en.wikipedia.org/wiki/Ziggurat_algorithm ), introduced by G. Marsaglia and W. W. Tsang.

Implementations§

source§

impl RNG

source

pub fn default() -> Result<RNG>

constructor

These are the RNG constructors. The first form sets the state to some pre-defined value, equal to 2**32-1 in the current implementation. The second form sets the state to the specified value. If you passed state=0 , the constructor uses the above default value instead to avoid the singular random number sequence, consisting of all zeros.

source

pub fn new(state: u64) -> Result<RNG>

constructor

These are the RNG constructors. The first form sets the state to some pre-defined value, equal to 2**32-1 in the current implementation. The second form sets the state to the specified value. If you passed state=0 , the constructor uses the above default value instead to avoid the singular random number sequence, consisting of all zeros.

§Overloaded parameters
§Parameters
  • state: 64-bit value used to initialize the RNG.

Trait Implementations§

source§

impl Boxed for RNG

source§

unsafe fn from_raw(ptr: <RNG as OpenCVFromExtern>::ExternReceive) -> Self

Wrap the specified raw pointer Read more
source§

fn into_raw(self) -> <RNG as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying raw pointer while consuming this wrapper. Read more
source§

fn as_raw(&self) -> <RNG as OpenCVTypeExternContainer>::ExternSend

Return the underlying raw pointer. Read more
source§

fn as_raw_mut(&mut self) -> <RNG as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying mutable raw pointer Read more
source§

impl Debug for RNG

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for RNG

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl RNGTrait for RNG

source§

fn as_raw_mut_RNG(&mut self) -> *mut c_void

source§

fn set_state(&mut self, val: u64)

source§

fn next(&mut self) -> Result<u32>

The method updates the state using the MWC algorithm and returns the next 32-bit random number.
source§

fn to_u8(&mut self) -> Result<u8>

Each of the methods updates the state using the MWC algorithm and returns the next random number of the specified type. In case of integer types, the returned number is from the available value range for the specified type. In case of floating-point types, the returned value is from [0,1) range.
source§

fn to_i8(&mut self) -> Result<i8>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
source§

fn to_u16(&mut self) -> Result<u16>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
source§

fn to_i16(&mut self) -> Result<i16>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
source§

fn to_u32(&mut self) -> Result<u32>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
source§

fn to_i32(&mut self) -> Result<i32>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
source§

fn to_f32(&mut self) -> Result<f32>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
source§

fn to_f64(&mut self) -> Result<f64>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
source§

fn apply(&mut self) -> Result<u32>

returns a random integer sampled uniformly from [0, N). Read more
source§

fn apply_range(&mut self, n: u32) -> Result<u32>

returns a random integer sampled uniformly from [0, N). Read more
source§

fn uniform(&mut self, a: i32, b: i32) -> Result<i32>

returns uniformly distributed integer random number from [a,b) range Read more
source§

fn uniform_f32(&mut self, a: f32, b: f32) -> Result<f32>

returns uniformly distributed integer random number from [a,b) range Read more
source§

fn uniform_f64(&mut self, a: f64, b: f64) -> Result<f64>

returns uniformly distributed integer random number from [a,b) range Read more
source§

fn fill( &mut self, mat: &mut impl ToInputOutputArray, dist_type: i32, a: &impl ToInputArray, b: &impl ToInputArray, saturate_range: bool ) -> Result<()>

Fills arrays with random numbers. Read more
source§

fn fill_def( &mut self, mat: &mut impl ToInputOutputArray, dist_type: i32, a: &impl ToInputArray, b: &impl ToInputArray ) -> Result<()>

Fills arrays with random numbers. Read more
source§

fn gaussian(&mut self, sigma: f64) -> Result<f64>

Returns the next random number sampled from the Gaussian distribution Read more
source§

impl RNGTraitConst for RNG

source§

fn as_raw_RNG(&self) -> *const c_void

source§

fn state(&self) -> u64

source§

fn equals(&self, other: &impl RNGTraitConst) -> Result<bool>

source§

impl Send for RNG

Auto Trait Implementations§

§

impl Freeze for RNG

§

impl RefUnwindSafe for RNG

§

impl !Sync for RNG

§

impl Unpin for RNG

§

impl UnwindSafe for RNG

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Mat> ModifyInplace for Mat
where Mat: Boxed,

source§

unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res ) -> Res

Helper function to call OpenCV functions that allow in-place modification of a Mat or another similar object. By passing a mutable reference to the Mat to this function your closure will get called with the read reference and a write references to the same Mat. This is of course unsafe as it breaks the Rust aliasing rules, but it might be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place modification is imgproc::threshold. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.