Assigning probability

This is a discussion on Assigning probability within the C++ Programming forums, part of the General Programming Boards category; Hi all, I am about to design a class for a project that I am doing, however I cannot work ...

  1. #1
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135

    Assigning probability

    Hi all,

    I am about to design a class for a project that I am doing, however I cannot work out how to approach the design.

    Basically I have a series of events that can occur, which I will probably store in an a vector as "descriptive" strings. But I want to be able to assign a probability (probably a percentage) of the events occurance.

    For instance, you may have an array of weather descriptions, and during summer there is only a 5% chance of it raining on any given day.

    Can anyone point me in the right direction?

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    You can generate random numbers in the range 0 to 100 easily enough.

    Say event1 has a 25% probability of occuring, and event2 has a 75% probability.
    Code:
    //pseudocode
    If randomnumber is between 0 and 25
         event1
    if randomnumber is between 26 and 100
         event2
    That wouldn't be horribly difficult to code into a class.
    Away.

  3. #3
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    Mmm, that's so simple it could work!

    Thanks.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    //pseudocode
    If randomnumber is between 0 and 25
         event1
    if randomnumber is between 26 and 100
         event2
    That's assuming the events are not independant. Otherwise it would look like this:
    Code:
    //pseudocode
    If randomnumber is between 0 and 25
         event1
    if randomnumber2 is between 0 and 75
         event2
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assigning Ability Scores
    By SteelySam in forum C++ Programming
    Replies: 1
    Last Post: 07-10-2008, 02:16 PM
  2. Replies: 5
    Last Post: 06-10-2007, 05:54 AM
  3. Assigning to Void Pointer
    By coder8137 in forum C Programming
    Replies: 7
    Last Post: 12-06-2006, 12:38 PM
  4. 0% probability == impossible?
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 09-01-2003, 03:48 PM
  5. Assigning the value of a const array to a normal array
    By Accident Prone in forum C++ Programming
    Replies: 6
    Last Post: 08-11-2003, 10:40 PM

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