fork download
  1. #include<iostream>
  2. #include<random>
  3. #include<chrono>
  4.  
  5. int main(){
  6. const unsigned MAX_RESULTS = 1000000;
  7. const unsigned LIMIT = 300;
  8. int buckets[30]={0};
  9.  
  10. unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  11. std::mt19937 die(seed);
  12. unsigned n_results = 0;
  13. while(n_results<MAX_RESULTS){
  14. unsigned sum = 0;
  15. while( (sum+=(1+die()%30))<LIMIT);
  16. buckets[sum-LIMIT]++;
  17. n_results++;
  18. }
  19.  
  20. for(unsigned i = 0; i<30; i++){
  21. std::cout<<LIMIT+i<<":\t"<< buckets[i]*30.0/MAX_RESULTS << std::endl;
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.22s 3296KB
stdin
Standard input is empty
stdout
300:	1.93905
301:	1.87497
302:	1.81374
303:	1.73919
304:	1.67901
305:	1.61079
306:	1.54398
307:	1.47282
308:	1.42236
309:	1.35942
310:	1.29084
311:	1.21584
312:	1.16586
313:	1.09626
314:	1.04436
315:	0.97257
316:	0.903
317:	0.83385
318:	0.77565
319:	0.708
320:	0.63615
321:	0.57612
322:	0.52203
323:	0.45039
324:	0.38463
325:	0.32118
326:	0.25875
327:	0.19245
328:	0.13278
329:	0.06396