#include <iostream>
#include <random>
#include <ctime>
#include <iomanip>
int main()
{
const int nrolls = 526 ;
const int divisor = 9 ;
const int ntrials = 4 ;
std::mt19937 generator( std::time(nullptr) ); // mersenne twister
std::cout << "bernoulli distribution - deadtime distortion (divided sample)\n\n" ;
std::cout << std::fixed << std::setprecision(2) ;
for( double p = 0.1 ; p < 0.95 ; p += 0.1 )
{
for( int n = 0 ; n < ntrials ; ++n )
{
std::cout << "bernoulli (" << p << ") x " << nrolls << '/' << divisor << ": " ;
std::bernoulli_distribution distribution(p);
int count = {0} ; // count number of trues
for( int i=1 ; i <= nrolls ; ++i )
if( distribution(generator) && i%divisor == 0 ) ++count ;
std::cout << std::setw(3) << count<< " (" << std::setw(5)
<< count * 100.0 / ( nrolls / divisor ) << "%)\n" ;
}
std::cout << '\n' ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cmFuZG9tPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxpb21hbmlwPgoKaW50IG1haW4oKQp7CiAgICBjb25zdCBpbnQgbnJvbGxzID0gNTI2IDsKCWNvbnN0IGludCBkaXZpc29yID0gOSA7Cgljb25zdCBpbnQgbnRyaWFscyA9IDQgOwoJc3RkOjptdDE5OTM3IGdlbmVyYXRvciggc3RkOjp0aW1lKG51bGxwdHIpICk7IC8vIG1lcnNlbm5lIHR3aXN0ZXIKCiAgICBzdGQ6OmNvdXQgPDwgImJlcm5vdWxsaSBkaXN0cmlidXRpb24gLSBkZWFkdGltZSBkaXN0b3J0aW9uIChkaXZpZGVkIHNhbXBsZSlcblxuIiA7CiAgICBzdGQ6OmNvdXQgPDwgc3RkOjpmaXhlZCA8PCBzdGQ6OnNldHByZWNpc2lvbigyKSA7CgogICAgZm9yKCBkb3VibGUgcCA9IDAuMSA7IHAgPCAwLjk1IDsgcCArPSAwLjEgKQogICAgewogICAgICAgIGZvciggaW50IG4gPSAwIDsgbiA8IG50cmlhbHMgOyArK24gKQogICAgICAgIHs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