fork(1) download
  1. #include <iostream>
  2. #include <random>
  3.  
  4. using namespace std;
  5.  
  6. int getNum(int N, double p)
  7. {
  8. static default_random_engine u(random_device{}());
  9. uniform_real_distribution<> r(0,1);
  10. double q = (1-p)/(N-1);
  11. return int(r(u)/q);
  12. }
  13.  
  14. int main(int argc, char * argv[])
  15. {
  16. int cnt[11] = {};
  17. for(int i = 0; i < 1000000; ++i)
  18. {
  19. cnt[getNum(11,0.001)]++;
  20. }
  21. for(int i: cnt) cout << i << endl;
  22. }
  23.  
Success #stdin #stdout 0.02s 5660KB
stdin
Standard input is empty
stdout
100360
99728
100164
100185
99781
99733
99894
100397
99359
99410
989