fork download
  1.  
  2. #include <iostream>
  3. #include <random>
  4.  
  5. #include <map>
  6. #include <iomanip>
  7.  
  8. int main()
  9. {
  10. const int nrolls = 10000; // number of experiments
  11.  
  12.  
  13. std::default_random_engine generator;
  14.  
  15. std::uniform_int_distribution<int> distribution(Min, Max);
  16.  
  17.  
  18.  
  19. std::map<int, int> histogram;
  20. for (int i = 0; i < nrolls; i++) {
  21. int number = distribution(generator);
  22. ++histogram[number];
  23. }
  24.  
  25. for (auto p : histogram) {
  26. std::cout << std::fixed << std::setprecision(1) << std::setw(2)
  27. << p.first << ' ' << std::string(p.second/(nrolls/(10*(Max-Min))), '*') << '\n';
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
10 ********
11 *********
12 *********
13 ********
14 *********
15 *********
16 *********
17 *********
18 ********
19 *********
20 *********