How to initialize boost :: random :: discrete_distribution using std :: vector?

I would like to initialize boost::random::discrete_distribution with std::vector<double> .

My problem is that if I initialize it with an array, as in the official example:

 double probabilities[] = { 0.5, 0.1, 0.1, 0.1, 0.1, 0.1 }; boost::random::discrete_distribution<> dist(probabilities); 

then it works fine.

However, if I initialize it with std::vector , then it behaves as if it had only one element with a probability of 1.0.

Can you tell me what is the correct way to initialize boost::random::discrete_distribution<> with a vector?

+6
source share
1 answer

The class seems to have a constructor that accepts a range of iterators . This will be used with such a vector:

 std::vector<double> probs = ...; boost::random::discrete_distribution<> dist(probs.begin(), probs.end()); 
+10
source

Source: https://habr.com/ru/post/900139/


All Articles