fork(9) download
  1. // bernoulli_distribution
  2. #include <iostream>
  3. #include <random>
  4.  
  5. int main()
  6. {
  7. const int nrolls=10000;
  8.  
  9. std::default_random_engine generator;
  10. std::bernoulli_distribution distribution(0.95);
  11.  
  12. int count=0; // count number of trues
  13.  
  14. for (int i=0; i<nrolls; ++i) if (distribution(generator)) ++count;
  15.  
  16. std::cout << "bernoulli_distribution (0.95) x 10000:" << std::endl;
  17. std::cout << "true: " << count << std::endl;
  18. std::cout << "false: " << nrolls-count << std::endl;
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
bernoulli_distribution (0.95) x 10000:
true:  9478
false: 522