fork(1) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <random>
  4.  
  5. using namespace std;
  6.  
  7. mt19937 gen(random_device{}());
  8. uniform_real_distribution<> dis(0.0, 1.0);
  9.  
  10. int howmuch()
  11. {
  12. int count = 0;
  13. for(int ok = 0; ok < 2; count++)
  14. if (dis(gen) < 0.2) ok++;
  15. return count;
  16. }
  17.  
  18. int main()
  19. {
  20. int total = 0, ok = 0;
  21. for(; total < 1000000;)
  22. {
  23. ok += howmuch();
  24. total++;
  25. }
  26. cout << double(ok)/total << "\r";
  27. }
  28.  
Success #stdin #stdout 0.2s 4560KB
stdin
Standard input is empty
stdout
9.99556