When rolling 2 six-sided die the most common result should be 7, with 2 and 12 as the least common results.
When I execute the code below, I get a high occurrence of the number 12 which is erroneous.
#include <iostream>
#include <iomanip>
#include <random>
#include <ctime>
#include <array>
using namespace std;
int main() {
default_random_engine engine(static_cast<unsigned int>(time(0)));
uniform_int_distribution<unsigned int> randomInt(1, 6);
const size_t arraySize{11};
array<unsigned int, arraySize> frequency{};
for (unsigned int roll{1}; roll <= 36'000'000; ++roll){
++frequency[randomInt(engine) + randomInt(engine)];
}
cout << "Face" << setw(24) << "Frequency" << endl;
for (size_t sum{2}; sum <= 12; ++sum) {
cout << setw(4) << sum << setw(24) << frequency[sum] << endl;
}
}
Below are a couple results:
Face Frequency
2 1001328
3 1997709
4 2999938
5 4000842
6 4998363
7 5998813
8 5003114
9 4001434
10 3000068
11 1999298
12 5197605
Face Frequency
2 1001328
3 1997709
4 2999938
5 4000842
6 4998363
7 5998813
8 5003114
9 4001434
10 3000068
11 1999298
12 5197605
Why are so many 12's being counted?
Aucun commentaire:
Enregistrer un commentaire