fork(8) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <cmath>
  5. #include <random>
  6.  
  7.  
  8. std::mt19937& GetRand()
  9. {
  10. std::random_device rd;
  11. std::mt19937 gen(rd());
  12. return gen;
  13. }
  14.  
  15. template <typename T>
  16. T Draw(T lo, T hi)
  17. {
  18. if (lo == hi)
  19. return lo;
  20.  
  21. if (hi < lo)
  22. std::swap(lo, hi);
  23.  
  24. std::uniform_int_distribution<T> d(lo, hi);
  25. return d(GetRand());
  26. }
  27.  
  28. template <typename T>
  29. T GaussNormal(T lo, T hi)
  30. {
  31. if (lo == hi)
  32. return lo;
  33.  
  34. if (hi < lo)
  35. std::swap(lo, hi);
  36.  
  37. std::normal_distribution<T> d(lo, hi);
  38. return d(GetRand());
  39. }
  40.  
  41. int MINMAX(int min, int value, int max)
  42. {
  43. register int tv;
  44.  
  45. tv = (min > value ? min : value);
  46. return (max < tv) ? max : tv;
  47. }
  48.  
  49.  
  50. int main()
  51. {
  52. int iSkillBonus, iNormalHitBonus;
  53. unsigned long long counter = 0;
  54.  
  55. for (;;)
  56. {
  57. iSkillBonus = MINMAX(-30, (GaussNormal(0.0f, 5.0f) + 0.5f), 30);
  58. if (abs(iSkillBonus) <= 20)
  59. iNormalHitBonus = -2 * iSkillBonus + abs(Draw(-8, 8) + Draw(-8, 8)) + Draw(1, 4);
  60. else
  61. iNormalHitBonus = -2 * iSkillBonus + Draw(1, 5);
  62.  
  63. counter += 1;
  64. if (iNormalHitBonus >= 58) ////if normal hit bonus is 55 or higher, the loop will stop
  65. break;
  66.  
  67.  
  68.  
  69. //you can delete this if you want to make it faster
  70. //cout << "normal hit bonus: " << iNormalHitBonus << endl;
  71. //cout << "skill bonus: " << iSkillBonus << endl;
  72. //
  73.  
  74. }
  75.  
  76. std::cout << "you've used " << counter << " changes" << std::endl;
  77.  
  78. return 0;
  79. }
Runtime error #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty