fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <functional>
  4. #include <random>
  5.  
  6. void a() { std::cout << "a "; }
  7. void b() { std::cout << "b "; }
  8. void c() { std::cout << "c "; }
  9. void d() { std::cout << "d "; }
  10. void e() { std::cout << "e "; }
  11.  
  12. int main()
  13. {
  14. std::vector<std::function<void()>> functions = {a,b,c,d,e};
  15.  
  16. std::random_device rd;
  17. std::mt19937 gen(rd());
  18. std::discrete_distribution<> d({10, 10, 10, 1, 10});
  19.  
  20. // call them randomly (with d() 10 times less likely)
  21. for(int n = 0; n < 30; ++n)
  22. functions[d(gen)]();
  23. }
  24.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
a e e c e b a b c e c b e c e b d e e b c e c c c a b e c b