fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <vector>
  4.  
  5. //for c++11 and later!
  6.  
  7. int main(){
  8.  
  9. static const int Rolls = 100000;
  10.  
  11. std::random_device rd;
  12. std::mt19937 mt(rd());
  13. std::discrete_distribution<> dist{ 1, 2, 1, 2, 1, 2 };//this is important!
  14.  
  15. std::vector<int> vec;
  16. vec.resize(6);
  17. for (auto& o : vec) o = 0;
  18.  
  19. for (int i = 0; i < Rolls; i++) vec[dist(mt)]++;
  20.  
  21. int j = 1;
  22. for (auto& i : vec) std::cout << j++ << ':' << i << std::endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 3476KB
stdin
Standard input is empty
stdout
1:11075
2:22112
3:11094
4:22430
5:11023
6:22266