#include <iostream>
#include <random>
#include <vector>
int main()
{
std::vector<double> weights{0.0, 1.0, 2.0};
std::size_t i(0);
std::discrete_distribution<> dist(weights.size(), weights.front(), weights.back(), [&weights, &i](double)
{
auto w = weights[i];
++i;
return w;
});
std::discrete_distribution<> dist2(weights.cbegin(), weights.cend());
for ( const auto& entry : dist.probabilities() )
{
std::cerr << entry << " ";
}
std::cerr << "\n";
for ( const auto& entry : dist2.probabilities() )
{
std::cerr << entry << " ";
}
std::cerr << "\n";
}
CgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxyYW5kb20+CiNpbmNsdWRlIDx2ZWN0b3I+CgppbnQgbWFpbigpCnsKICAgc3RkOjp2ZWN0b3I8ZG91YmxlPiB3ZWlnaHRzezAuMCwgMS4wLCAyLjB9OwogICBzdGQ6OnNpemVfdCBpKDApOwogICBzdGQ6OmRpc2NyZXRlX2Rpc3RyaWJ1dGlvbjw+IGRpc3Qod2VpZ2h0cy5zaXplKCksIHdlaWdodHMuZnJvbnQoKSwgd2VpZ2h0cy5iYWNrKCksIFsmd2VpZ2h0cywgJmldKGRvdWJsZSkKICAgewogICAgICBhdXRvIHcgPSB3ZWlnaHRzW2ldOwogICAgICArK2k7CiAgICAgIHJldHVybiB3OwogICB9KTsKICAgc3RkOjpkaXNjcmV0ZV9kaXN0cmlidXRpb248PiBkaXN0Mih3ZWlnaHRzLmNiZWdpbigpLCB3ZWlnaHRzLmNlbmQoKSk7CiAgIGZvciAoIGNvbnN0IGF1dG8mIGVudHJ5IDogZGlzdC5wcm9iYWJpbGl0aWVzKCkgKQogICB7CiAgICAgIHN0ZDo6Y2VyciA8PCBlbnRyeSA8PCAiICI7CiAgIH0KICAgc3RkOjpjZXJyIDw8ICJcbiI7CiAgIGZvciAoIGNvbnN0IGF1dG8mIGVudHJ5IDogZGlzdDIucHJvYmFiaWxpdGllcygpICkKICAgewogICAgICBzdGQ6OmNlcnIgPDwgZW50cnkgPDwgIiAiOwogICB9CiAgIHN0ZDo6Y2VyciA8PCAiXG4iOwp9