Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <chrono>
  4.  
  5. void trial(int denominator, int loops) {
  6. std::random_device rd; // obtain a random number from hardware
  7. std::mt19937 rng(rd()); // seed the generator
  8. std::uniform_int_distribution<> oneToX(1, denominator); // define the range
  9. int orb = 0;
  10. int dormant1 = 0;
  11. int dormant2 = 0;
  12. int dormant3 = 0;
  13. int dormant4 = 0;
  14. int totalRanges = 0; // total times the range has been counted and resetted
  15.  
  16. int orbCounter = 0; // start of the range
  17. int dormant1Counter = 0;
  18. int dormant2Counter = 0;
  19. int dormant3Counter = 0;
  20. int dormant4Counter = 0;
  21.  
  22. double averageTotalRares = 0;
  23. auto startTime = std::chrono::steady_clock::now();
  24.  
  25. for (int i=0; i<loops; ++i) {
  26. int value = oneToX(rng);
  27. if (value <= 75 ) {
  28. orb += 1;
  29. orbCounter += 1;
  30. }
  31. if (value > 75 && value <=85) {
  32. dormant1 += 1;
  33. dormant1Counter += 1;
  34. }
  35. if (value > 85 && value <=95) {
  36. dormant2 += 1;
  37. dormant2Counter += 1;
  38. }
  39. if (value > 95 && value <=105) {
  40. dormant3 += 1;
  41. dormant3Counter += 1;
  42. }
  43. if (value > 105 && value <=115) {
  44. dormant4 += 1;
  45. dormant4Counter += 1;
  46. }
  47. if (orb>=3 && dormant1>0 && dormant2>0 && dormant3>0 && dormant4>0) {
  48. orb = 0;
  49. dormant1 = 0;
  50. dormant2 = 0;
  51. dormant3 = 0;
  52. dormant4 = 0;
  53. totalRanges += 1;
  54. }
  55. }
  56.  
  57. auto endTime = std::chrono::steady_clock::now();
  58. std::cout <<"loops : " << loops <<std::endl;
  59. std::cout <<"orb : " << orbCounter <<std::endl;
  60. std::cout <<"dormant1 : " << dormant1Counter <<std::endl;
  61. std::cout <<"dormant2 : " << dormant2Counter <<std::endl;
  62. std::cout <<"dormant3 : " << dormant3Counter <<std::endl;
  63. std::cout <<"dormant4 : " << dormant4Counter <<std::endl;
  64. std::cout <<"totalRanges : " << totalRanges <<std::endl;
  65. averageTotalRares = (double) loops / (double) totalRanges;
  66. std::cout << "loops / totalRanges : " << averageTotalRares << std::endl << "time elapsed in seconds : " << std::chrono::duration_cast<std::chrono::seconds>(endTime - startTime).count() << "s" << std::endl;
  67. };
  68.  
  69. int main() {
  70. trial(115, 1e7);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement