increasing chance.

This is a discussion on increasing chance. within the C++ Programming forums, part of the General Programming Boards category; Hey, I'm trying to make a text-based simple virtual pet in c++. very basic, i'm just trying to get the ...

  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, 01:42 PM
  3. Replies: 8
    Last Post: 04-07-2004, 02:29 PM
  4. chance assignment of random
    By scuba22 in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2002, 12:52 PM
  5. increasing prob with randoms
    By scuba22 in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2002, 08:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21