ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::utility::random::DiscreteGenerator< T > Class Template Reference

#include <Random.h>

Public Member Functions

template<typename InputIt >
 DiscreteGenerator (InputIt first, InputIt last)
 
operator() ()
 Call this to generate a discretely distributed integer value. More...
 

Protected Attributes

std::discrete_distribution< T > distribution_
 

Detailed Description

template<typename T>
class cloudViewer::utility::random::DiscreteGenerator< T >

Generate discretely distributed integer values according to a range of weight values. This class is globally seeded by utility::random::Seed(). This class is a wrapper around std::discrete_distribution.

Example:

// Globally seed cloudViewer. This will affect all random functions.
// Weighted random choice of size_t
std::vector<double> weights{1, 2, 3, 4, 5};
utility::random::DiscreteGenerator<size_t> gen(weights.cbegin(),
weights.cend()); for (size_t i = 0; i < 10; i++) {
std::cout << gen() << std::endl;
}
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
void Seed(const int seed)
Set CloudViewer global random seed.
Definition: Random.cpp:53

Definition at line 197 of file Random.h.

Constructor & Destructor Documentation

◆ DiscreteGenerator()

template<typename T >
template<typename InputIt >
cloudViewer::utility::random::DiscreteGenerator< T >::DiscreteGenerator ( InputIt  first,
InputIt  last 
)
inline

Generate discretely distributed integer values according to a range of weight values.

Parameters
firstThe iterator or pointer pointing to the first element in the range of weights.
lastThe iterator or pointer pointing to one past the last element in the range of weights.

Definition at line 206 of file Random.h.

References LogError.

Member Function Documentation

◆ operator()()

template<typename T >
T cloudViewer::utility::random::DiscreteGenerator< T >::operator() ( )
inline

Call this to generate a discretely distributed integer value.

Definition at line 214 of file Random.h.

References cloudViewer::utility::random::DiscreteGenerator< T >::distribution_, cloudViewer::utility::random::GetEngine(), and cloudViewer::utility::random::GetMutex().

Member Data Documentation

◆ distribution_

template<typename T >
std::discrete_distribution<T> cloudViewer::utility::random::DiscreteGenerator< T >::distribution_
protected

The documentation for this class was generated from the following file: