#include <vector>
#include <random>
#include <iostream>
#include <iomanip>
struct Die
{
Die(unsigned faces = 6) : _faces(faces), _die(std::random_device()()) {}
Die(const Die& d) : _faces(d._faces), _die(std::random_device()()) {}
unsigned operator()() { return std::uniform_int_distribution<unsigned>(1, _faces)(_die); }
private:
unsigned _faces;
std::mt19937 _die;
};
int main()
{
const unsigned trials = 100000;
const unsigned faces = 6;
const unsigned num_dice = 6;
std::vector<Die> dice(num_dice, Die(faces));
std::vector<unsigned> counts(faces * num_dice + 1);
for (unsigned i = 0; i < trials; ++i)
{
unsigned rolls = 0;
for (auto& die : dice)
rolls += die();
++counts[rolls];
}
std::cout << "Counts\n";
for (unsigned i = num_dice; i < counts.size(); ++i)
{
std::cout << std::setw(2) << i << ": ";
std::cout << std::setw(6) << counts[i] << " - ";
std::cout << std::setw(5) << std::fixed << std::setprecision(2);
std::cout << (counts[i] / (double) trials)*100.0 << "%\n";
}
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHJhbmRvbT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KCnN0cnVjdCBEaWUKewogICAgRGllKHVuc2lnbmVkIGZhY2VzID0gNikgOiBfZmFjZXMoZmFjZXMpLCBfZGllKHN0ZDo6cmFuZG9tX2RldmljZSgpKCkpIHt9CiAgICBEaWUoY29uc3QgRGllJiBkKSA6IF9mYWNlcyhkLl9mYWNlcyksIF9kaWUoc3RkOjpyYW5kb21fZGV2aWNlKCkoKSkge30KCiAgICB1bnNpZ25lZCBvcGVyYXRvcigpKCkgeyByZXR1cm4gc3RkOjp1bmlmb3JtX2ludF9kaXN0cmlidXRpb248dW5zaWduZWQ+KDEsIF9mYWNlcykoX2RpZSk7IH0KCnByaXZhdGU6CiAgICB1bnNpZ25lZCBfZmFjZXM7CiAgICBzdGQ6Om10MTk5MzcgX2RpZTsKfTsKCmludCBtYWluKCkKewogICAgY29uc3QgdW5zaWduZWQgdHJpYWxzID0gMTAw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