Thread: increasing chance.

  1. #1
    davee
    Guest

    Question 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.

  2. #2
    Registered User quagsire's Avatar
    Join Date
    Jun 2002
    Posts
    60
    Code:
    int num = random(good+bad) + 1;
    if num > good 
     dobad();
    else 
     dogood();

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    what's random, do you mean rand().
    and if there is random() in what header file it's defined?

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    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

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    davee
    Guest
    Thanks. Much appreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Second Chance Algorithm
    By Aga^^ in forum C++ Programming
    Replies: 4
    Last Post: 12-23-2008, 08:03 AM
  2. Probability Help - Math Geniuses Here
    By The Brain in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 06-09-2005, 12:42 PM
  3. Replies: 8
    Last Post: 04-07-2004, 01:29 PM
  4. chance assignment of random
    By scuba22 in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2002, 11:52 AM
  5. increasing prob with randoms
    By scuba22 in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2002, 07:06 AM