#include #include #include // for random items #include // for bind #include #include using namespace std; int main(int argc, char * argv[]) { int engineChoice = 0; int iterations = 1'000'000; for (int i{1}; i < argc; ) { if (!strcmp(argv[i], "-e") ) { ++i; if (i < argc) { engineChoice = atoi(argv[i]); if (engineChoice < 0 or engineChoice > 3) { engineChoice = 0; } ++i; } } else if (!strcmp(argv[i], "-i")) { ++i; if (i < argc) { iterations = atoi(argv[i]); if (iterations < 0 ) { iterations = 1'000'000; } ++i; } } else { ++i; } } // construct a seed and a random number generaton engine random_device seeder; const auto seed {seeder.entropy() ? seeder(): time(nullptr)}; mt19937 engine{static_cast(seed)}; // construct four different distributions using that engine. uniform_int_distribution uniformIntDistribution{1,20}; auto uniformIntGenerator{bind(uniformIntDistribution, engine)}; uniform_real_distribution uniformRealDistribution{1.0, 21.0}; auto uniformRealGenerator{bind(uniformRealDistribution, engine)}; normal_distribution normalDistribution{10.0, 2.2}; auto normalGenerator{bind(normalDistribution, engine)}; poisson_distribution poissonDistribution{5}; auto poissonGenerator{bind(poissonDistribution, engine)}; // just a quick demo cout << "a uniform float is " << uniformRealGenerator(engine) << endl; // a place to store the results map counts; for(int i{0}; i < iterations; ++i) { int result; switch(engineChoice){ case 0: result = static_cast (uniformIntGenerator()); break; case 1: result = static_cast (uniformRealGenerator()); break; case 2: result = static_cast (normalGenerator()); break; case 3: result = static_cast (poissonGenerator()); break; default: result = static_cast (uniformIntGenerator()); } ++(counts[result]); } for(auto x = counts.begin(); x != end(counts); x++) { cout <first << setw(10) << x->second << endl; } cout << endl; return 0; }