#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
bool askOracle(float percentChance)
{
// Decides if a decision should
// be done (true/false), when a
// certain Percent Chance is given
//
// -> Don't forget to call randomize
// everyone once in a while!
// generate random number between 0 and 99
int randomNumber = rand() % 100;
// scale it so it's between 0 and 1
float randomResult = float(randomNumber) * 0.01f;
// compare to see if it had "happened"
return randomResult < percentChance;
}
void dropItems()
{
// our event has a 90% chance (which means 0.90f)
// so lets ask the "oracle" to see if it happens
// or not
if (askOracle(0.90f)) {
// drop coins or a sword or whatever
std::cout << "it happened!" << std::endl;
} else {
std::cout << "it didn't happen!" << std::endl;
}
}
int main(int argc, const char * argv[])
{
srand(time(0));
for (int i = 0; i < 10; ++i)
dropItems();
return 0;
}