Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <chrono>
- void trial(int denominator, int loops) {
- std::random_device rd; // obtain a random number from hardware
- std::mt19937 rng(rd()); // seed the generator
- std::uniform_int_distribution<> oneToX(1, denominator); // define the range
- int orb = 0;
- int dormant1 = 0;
- int dormant2 = 0;
- int dormant3 = 0;
- int dormant4 = 0;
- int totalRanges = 0; // total times the range has been counted and resetted
- int orbCounter = 0; // start of the range
- int dormant1Counter = 0;
- int dormant2Counter = 0;
- int dormant3Counter = 0;
- int dormant4Counter = 0;
- double averageTotalRares = 0;
- auto startTime = std::chrono::steady_clock::now();
- for (int i=0; i<loops; ++i) {
- int value = oneToX(rng);
- if (value <= 75 ) {
- orb += 1;
- orbCounter += 1;
- }
- if (value > 75 && value <=85) {
- dormant1 += 1;
- dormant1Counter += 1;
- }
- if (value > 85 && value <=95) {
- dormant2 += 1;
- dormant2Counter += 1;
- }
- if (value > 95 && value <=105) {
- dormant3 += 1;
- dormant3Counter += 1;
- }
- if (value > 105 && value <=115) {
- dormant4 += 1;
- dormant4Counter += 1;
- }
- if (orb>=3 && dormant1>0 && dormant2>0 && dormant3>0 && dormant4>0) {
- orb = 0;
- dormant1 = 0;
- dormant2 = 0;
- dormant3 = 0;
- dormant4 = 0;
- totalRanges += 1;
- }
- }
- auto endTime = std::chrono::steady_clock::now();
- std::cout <<"loops : " << loops <<std::endl;
- std::cout <<"orb : " << orbCounter <<std::endl;
- std::cout <<"dormant1 : " << dormant1Counter <<std::endl;
- std::cout <<"dormant2 : " << dormant2Counter <<std::endl;
- std::cout <<"dormant3 : " << dormant3Counter <<std::endl;
- std::cout <<"dormant4 : " << dormant4Counter <<std::endl;
- std::cout <<"totalRanges : " << totalRanges <<std::endl;
- averageTotalRares = (double) loops / (double) totalRanges;
- std::cout << "loops / totalRanges : " << averageTotalRares << std::endl << "time elapsed in seconds : " << std::chrono::duration_cast<std::chrono::seconds>(endTime - startTime).count() << "s" << std::endl;
- };
- int main() {
- trial(115, 1e7);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement