fork(2) download
  1. #include <iostream>
  2. #include <random>
  3. #include <ctime>
  4. #include <iomanip>
  5.  
  6. int main()
  7. {
  8. const int nrolls = 526 ;
  9. const int divisor = 9 ;
  10. const int ntrials = 4 ;
  11. std::mt19937 generator( std::time(nullptr) ); // mersenne twister
  12.  
  13. std::cout << "bernoulli distribution - deadtime distortion (divided sample)\n\n" ;
  14. std::cout << std::fixed << std::setprecision(2) ;
  15.  
  16. for( double p = 0.1 ; p < 0.95 ; p += 0.1 )
  17. {
  18. for( int n = 0 ; n < ntrials ; ++n )
  19. {
  20. std::cout << "bernoulli (" << p << ") x " << nrolls << '/' << divisor << ": " ;
  21. std::bernoulli_distribution distribution(p);
  22.  
  23. int count = {0} ; // count number of trues
  24. for( int i=1 ; i <= nrolls ; ++i )
  25. if( distribution(generator) && i%divisor == 0 ) ++count ;
  26.  
  27. std::cout << std::setw(3) << count<< " (" << std::setw(5)
  28. << count * 100.0 / ( nrolls / divisor ) << "%)\n" ;
  29. }
  30. std::cout << '\n' ;
  31. }
  32. }
  33.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
bernoulli distribution - deadtime distortion (divided sample)

bernoulli (0.10) x 526/9:   6 (10.34%)
bernoulli (0.10) x 526/9:   2 ( 3.45%)
bernoulli (0.10) x 526/9:   4 ( 6.90%)
bernoulli (0.10) x 526/9:  10 (17.24%)

bernoulli (0.20) x 526/9:  12 (20.69%)
bernoulli (0.20) x 526/9:  16 (27.59%)
bernoulli (0.20) x 526/9:  10 (17.24%)
bernoulli (0.20) x 526/9:  15 (25.86%)

bernoulli (0.30) x 526/9:  17 (29.31%)
bernoulli (0.30) x 526/9:  14 (24.14%)
bernoulli (0.30) x 526/9:  22 (37.93%)
bernoulli (0.30) x 526/9:  17 (29.31%)

bernoulli (0.40) x 526/9:  26 (44.83%)
bernoulli (0.40) x 526/9:  28 (48.28%)
bernoulli (0.40) x 526/9:  19 (32.76%)
bernoulli (0.40) x 526/9:  26 (44.83%)

bernoulli (0.50) x 526/9:  33 (56.90%)
bernoulli (0.50) x 526/9:  23 (39.66%)
bernoulli (0.50) x 526/9:  35 (60.34%)
bernoulli (0.50) x 526/9:  24 (41.38%)

bernoulli (0.60) x 526/9:  31 (53.45%)
bernoulli (0.60) x 526/9:  35 (60.34%)
bernoulli (0.60) x 526/9:  38 (65.52%)
bernoulli (0.60) x 526/9:  42 (72.41%)

bernoulli (0.70) x 526/9:  38 (65.52%)
bernoulli (0.70) x 526/9:  39 (67.24%)
bernoulli (0.70) x 526/9:  30 (51.72%)
bernoulli (0.70) x 526/9:  40 (68.97%)

bernoulli (0.80) x 526/9:  48 (82.76%)
bernoulli (0.80) x 526/9:  51 (87.93%)
bernoulli (0.80) x 526/9:  49 (84.48%)
bernoulli (0.80) x 526/9:  50 (86.21%)

bernoulli (0.90) x 526/9:  52 (89.66%)
bernoulli (0.90) x 526/9:  51 (87.93%)
bernoulli (0.90) x 526/9:  50 (86.21%)
bernoulli (0.90) x 526/9:  55 (94.83%)