You can now construct vector with weights:
std::vector< double> weights( n);
for( int i = 0; i < n; ++i) {
weights[i] = pdf( i + 1);
}
std::default_random_engine generator;
std::discrete_distribution<int> distribution( weights.begin(), weights.end()) ;
int prob[n]={};
for ( int i=0; i<n; ++i) {
int number = distribution( generator);
++prob[number];
}
This will generate starting from 0, this is how discrete_distribution works, but you can assume with no loss of correctness that values are calculated for a range 1, ..., n
(weights are calculated for 1, ..., n
).