Version: SMASH-3.1
smash::random::discrete_dist< T > Class Template Reference

#include <random.h>

template<typename T>
class smash::random::discrete_dist< T >

Discrete distribution with weight given by probability vector.

Definition at line 258 of file random.h.

Public Member Functions

 discrete_dist ()
 Default discrete distribution. More...
 
 discrete_dist (const std::vector< T > &plist)
 Construct from probability vector. More...
 
 discrete_dist (std::initializer_list< T > l)
 Construct from probability list. More...
 
void reset_weights (const std::vector< T > &plist)
 Reset the discrete distribution from a new probability list. More...
 
int operator() ()
 Draw a random number from the discrete distribution. More...
 

Private Attributes

std::discrete_distribution distribution
 The distribution object that is being used. More...
 

Constructor & Destructor Documentation

◆ discrete_dist() [1/3]

template<typename T >
smash::random::discrete_dist< T >::discrete_dist ( )
inline

Default discrete distribution.

Always draws 0.

Definition at line 264 of file random.h.

264 : distribution({1.0}) {}
std::discrete_distribution distribution
The distribution object that is being used.
Definition: random.h:290

◆ discrete_dist() [2/3]

template<typename T >
smash::random::discrete_dist< T >::discrete_dist ( const std::vector< T > &  plist)
inlineexplicit

Construct from probability vector.

Parameters
plistVector with probabilities such that P(i) = vec[i]

Definition at line 269 of file random.h.

270  : distribution(plist.begin(), plist.end()) {}

◆ discrete_dist() [3/3]

template<typename T >
smash::random::discrete_dist< T >::discrete_dist ( std::initializer_list< T >  l)
inlineexplicit

Construct from probability list.

Parameters
lInitializer list with probabilities such that P(i) = l[i]

Definition at line 275 of file random.h.

275 : distribution(l) {}

Member Function Documentation

◆ reset_weights()

template<typename T >
void smash::random::discrete_dist< T >::reset_weights ( const std::vector< T > &  plist)
inline

Reset the discrete distribution from a new probability list.

Parameters
plistVector with probabilities such that P(i) = vec[i]

Definition at line 280 of file random.h.

280  {
281  distribution = std::discrete_distribution<>(plist.begin(), plist.end());
282  }

◆ operator()()

template<typename T >
int smash::random::discrete_dist< T >::operator() ( )
inline

Draw a random number from the discrete distribution.

Returns
Sampled value

Definition at line 286 of file random.h.

286 { return distribution(engine); }
Engine engine
The engine that is used commonly by all distributions.
Definition: random.cc:18

Member Data Documentation

◆ distribution

template<typename T >
std::discrete_distribution smash::random::discrete_dist< T >::distribution
private

The distribution object that is being used.

Definition at line 290 of file random.h.


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