fork download
  1.  
  2. #include <random>
  3. #include <iostream>
  4. #include <algorithm>
  5. //#include <time.h>
  6.  
  7. const int N=6;
  8. const int X=10000;
  9. const int C=10000;
  10.  
  11. void test(::std::vector<int>& c, unsigned int seed, unsigned int (*f)(::std::mt19937&))
  12. {
  13. ::std::mt19937 g(seed);
  14. int n[N] ={};
  15. for( int i=0; i < X; ++i )
  16. {
  17. n[ f(g) ]++;
  18. }
  19. int r[N] = {};
  20. for( int i=0; i < N; ++i ) r[i] = i;
  21. ::std::sort(r, r+N, [&](int a, int b){ return n[a] > n[b]; });
  22. for( int i=0; i < N; ++i )
  23. {
  24. c[r[i]] += N/2 - i;
  25. }
  26. }
  27.  
  28. int main(int, char**)
  29. {
  30. // ::std::mt19937 rd(static_cast<unsigned int>(time(NULL)));
  31. ::std::random_device rd;
  32. ::std::vector<int> c1(N), c2(N);
  33. for( int j=0; j < C; ++j )
  34. {
  35. unsigned int s = rd();
  36. test(c1, s, [](::std::mt19937& g){ return g()%N; });
  37. test(c2, s, [](::std::mt19937& g){ return ::std::uniform_int_distribution<unsigned int>(0, N-1)(g); });
  38. }
  39. for( int i=0; i < N; ++i )
  40. {
  41. ::std::cout << i << ": " << c1[i] << ", " << c2[i] << ::std::endl;
  42. }
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 4.1s 3032KB
stdin
Standard input is empty
stdout
0: 5171, 5245
1: 5216, 5385
2: 5154, 4833
3: 4907, 4974
4: 4645, 4757
5: 4907, 4806