Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- #include <ctime>
- #include <cstdlib>
- #include <windows.h>
- #define FLT_EPSILON 1.192092896e-07F
- #define RAND_MAX 0x7fff
- using namespace std;
- int number(int from, int to)
- {
- if (from > to)
- {
- int tmp = from;
- from = to;
- to = tmp;
- }
- int returnValue = 0;
- if ((to - from + 1) != 0)
- {
- returnValue = ((rand() % (to - from + 1)) + from);
- }
- return returnValue;
- }
- int MINMAX(int min, int value, int max)
- {
- register int tv;
- tv = (min > value ? min : value);
- return (max < tv) ? max : tv;
- }
- double uniform_random(double a, double b)
- {
- return rand() / (RAND_MAX + 1.f) * (b - a) + a;
- }
- float gauss_random(float avg, float sigma)
- {
- static bool haveNextGaussian = false;
- static float nextGaussian = 0.0f;
- if (haveNextGaussian)
- {
- haveNextGaussian = false;
- return nextGaussian * sigma + avg;
- }
- else
- {
- double v1, v2, s;
- do {
- //v1 = 2 * nextDouble() - 1; // between -1.0 and 1.0
- //v2 = 2 * nextDouble() - 1; // between -1.0 and 1.0
- v1 = uniform_random(-1.f, 1.f);
- v2 = uniform_random(-1.f, 1.f);
- s = v1 * v1 + v2 * v2;
- } while (s >= 1.f || fabs(s) < FLT_EPSILON);
- double multiplier = sqrtf(-2 * logf(s) / s);
- nextGaussian = v2 * multiplier;
- haveNextGaussian = true;
- return v1 * multiplier * sigma + avg;
- }
- }
- int main()
- {
- int iSkillBonus, iNormalHitBonus;
- unsigned long long counter = 0;
- srand(time(NULL));
- for (;;)
- {
- iSkillBonus = MINMAX(-30, (int)(gauss_random(0, 5) + 0.5f), 30);
- if (abs(iSkillBonus) <= 20)
- iNormalHitBonus = -2 * iSkillBonus + abs(number(-8, 8) + number(-8, 8)) + number(1, 4);
- else
- iNormalHitBonus = -2 * iSkillBonus + number(1, 5);
- counter += 1;
- if (iNormalHitBonus >= 55) ////if normal hit bonus is 55 or higher, the loop will stop
- break;
- Sleep(1); //how long you will wait between draws
- //you can delete this if you want to make it faster
- cout << "normal hit bonus: " << iNormalHitBonus << endl;
- cout << "skill bonus: " << iSkillBonus << endl;
- //
- }
- cout << "you've used " << counter << " changes" << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment