Created
August 22, 2014 14:03
-
-
Save nehalist/191b281a0208629ec807 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
class RandomNumberGenerator { | |
public: | |
bool found; | |
int tries; | |
int current; | |
RandomNumberGenerator() { | |
this->tries = 0; | |
this->found = false; | |
// Seed that shit | |
srand(time(NULL)); | |
} | |
void start() { | |
int rnd = (rand() % 100 + 1); | |
this->current = rnd; | |
if(rnd == 1) { | |
this->found = true; | |
} | |
this->tries++; | |
} | |
void reset() { | |
this->found = false; | |
this->tries = 0; | |
this->current = 0; | |
} | |
}; | |
int main() { | |
RandomNumberGenerator rng; | |
/*do { | |
rng.start(); | |
std::cout << "Current: " << rng.current << std::endl; | |
if(rng.found) { | |
std::cout << "Found after " << rng.tries << " tries" << std::endl; | |
} | |
} while( ! rng.found); */ | |
long long iterations = 0; | |
do { | |
iterations++; | |
rng.start(); | |
for(int i = 1; i <= 1603; i++) { | |
if(rng.found) { | |
std::cout << "Found after " << rng.tries << std::endl; | |
rng.reset(); | |
break; | |
} | |
} | |
} while(rng.tries != 1603); | |
std::cout << "Unlucky streak after " << iterations << " iterations" << std::endl; | |
system("PAUSE"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment