-
increasing chance.
Hey,
I'm trying to make a text-based simple virtual pet in c++. very basic, i'm just trying to get the skeleton of it at the moment. The problem I am having is increasing the likliness of the pet performing a good action the higher a number is.
For example, i have a class and good = 20, and bad = 10. Good is 10 more than bad, so i want the more of a difference there is, the more likely the pet will perform an action you ask, i.e sit. Also the other way around. If bad is more, it is more likely the dog will disobey.
I've been trying random mathematical ways but I can't get what i want. To me it seems pretty much impossible, but I don't know much. Could someone please help/point me in the right direction? thanks.
-
Code:
int num = random(good+bad) + 1;
if num > good
dobad();
else
dogood();
-
what's random, do you mean rand().
and if there is random() in what header file it's defined?
-
Attention all patrons, you are now entering a compiler specific region filled with mods with their bashin' sticks and 'FAQ' branded on their foreheads, thankyou for shopping at WeDontGiveAShat department store :D
-
Try working out the percentage chance of it being good (or bad), then get a random number between 1 and 100, and test it against the percentage.
For example, if there's a 70% change of it being good, random numbers between 1-70 would all be good, 71 - 100 would be bad.
-
Thanks. Much appreciated :)