fork(5) download
  1.  
  2.  
  3. #include <iostream>
  4. #include <random>
  5. #include <vector>
  6.  
  7. int main()
  8. {
  9. std::vector<double> weights{0.0, 1.0, 2.0};
  10. std::size_t i(0);
  11. std::discrete_distribution<> dist(weights.size(), weights.front(), weights.back(), [&weights, &i](double)
  12. {
  13. auto w = weights[i];
  14. ++i;
  15. return w;
  16. });
  17. std::discrete_distribution<> dist2(weights.cbegin(), weights.cend());
  18. for ( const auto& entry : dist.probabilities() )
  19. {
  20. std::cerr << entry << " ";
  21. }
  22. std::cerr << "\n";
  23. for ( const auto& entry : dist2.probabilities() )
  24. {
  25. std::cerr << entry << " ";
  26. }
  27. std::cerr << "\n";
  28. }
Success #stdin #stdout #stderr 0s 3472KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
0 0.333333 0.666667 
0 0.333333 0.666667