>>11704995#include <iostream>
#include <random>
#include <thread>
#include <chrono>
#include <stdint.h>
#include <vector>
std::mt19937_64& get_random_gen_ref() {
thread_local static std::random_device rd;
thread_local static size_t thread_id = std::hash<std::thread::id>{}(std::this_thread::get_id());
thread_local static long long time = std::chrono::high_resolution_clock::now().time_since_epoch().count();
thread_local static std::seed_seq seeds{
static_cast<uint_least32_t>(time >> 32), static_cast<uint_least32_t>(time),
static_cast<uint_least32_t>(thread_id >> 32), static_cast<uint_least32_t>(thread_id),
rd(), rd(), rd(), rd(), rd(), rd()
};
thread_local static std::mt19937_64 mt{seeds};
return mt;
}
int random_range(int a, int b){ return std::uniform_int_distribution<>{a,b}(get_random_gen_ref()); }
int main()
{
enum Ball {silver = 0, gold =1};
using Box = std::vector<Ball>;
Box boxes[3] {
{silver, silver, silver, silver, silver, silver, silver, silver, silver, silver},
{silver, silver, silver, silver, silver, silver, silver, silver, silver, gold},
{gold, gold, gold, gold, gold, gold, gold, gold, gold, gold}
};
int possible_outcomes=0;
int event=0;
for(int i = 0; i<9000000; ++i){
const Box & box = boxes[random_range(0,2)];
if(box[random_range(0,box.size()-1)]==gold){
++possible_outcomes;
if(boxes[2] == box)
++event;
}
}
std::cout<<"Events: "<<event<<"\nOut of: "<<possible_outcomes <<"\nRatio: " << static_cast<double>(event)/possible_outcomes <<std::endl;
}