fork download
  1. #include <random>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <iomanip>
  6.  
  7. int const width = 30;
  8. int const samples = 50000;
  9. double const stretch = 20.;
  10.  
  11. int main(int argc, char * argv[])
  12. {
  13. std::mt19937 gen;
  14. std::normal_distribution<> dist(0.8, 0.2);
  15.  
  16. std::vector<unsigned> hist(width);
  17.  
  18. for(size_t i = 0; i < samples; ++i)
  19. {
  20. int v = dist(gen) * stretch;
  21. if(v > 0. && v < width)
  22. ++hist[v];
  23. }
  24.  
  25. int fakt = *std::max_element(hist.begin(), hist.end()) / width;
  26.  
  27. for(size_t i = 0; i < width; ++i)
  28. std::cout << std::setw(4) << i / stretch << ": " << std::string(hist[i] / fakt, '*') << '\n';
  29. }
  30.  
  31.  
Success #stdin #stdout 0.01s 3464KB
stdin
Standard input is empty
stdout
   0: 
0.05: 
 0.1: 
0.15: 
 0.2: 
0.25: 
 0.3: *
0.35: ***
 0.4: ****
0.45: ********
 0.5: ***********
0.55: ****************
 0.6: ********************
0.65: *************************
 0.7: ****************************
0.75: *****************************
 0.8: ******************************
0.85: ****************************
 0.9: ************************
0.95: *******************
   1: ***************
1.05: ***********
 1.1: *******
1.15: *****
 1.2: ***
1.25: *
 1.3: *
1.35: 
 1.4: 
1.45: