Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Monte Carlo method

  1. Jan 31, 2009 #1
    Hello guys, I need some help on my AP CS class assignment.
    The assignment is as follows:

    "Write a program that uses the Monte Carlo sampling method to estimate the average number of bottles of Boost someone would have to drink to win a prize. There is a one in five chance that a bottle cap will have a prize.

    *Determine how many times a die must be rolled in order to win a prize. (This represents one

    *Calculate the average number of times a die must be rolled in order to win a prize "

    I am OK with the programming aspect of the assignment, I just need to get the concept of how Monte Carlos will be set up in this case. As far as I know, in Monte Carlos you have to approximate a range of values (min, max) for the uncertain parameters, then iteratively run the "simulation" substituting random numbers within the specified range in place of the uncertain parameters. How will the model be represented in this case? Any help is appreciated. :)
  2. jcsd
  3. Feb 3, 2009 #2
    If you keep providing hints, maybe I could help you.

  4. Feb 3, 2009 #3
    In the battleship game reference I posted, there would be two arrays, one for each player.

    Code (Text):

    double rgPlayerValuesA[nRows][nCols] = { 0.0 };
    double rgPlayerValuesB[nRows][nCols] = { 0.0 };
  5. Feb 4, 2009 #4


    User Avatar

    Staff: Mentor

    Simulate process of buying Boost till you win the prize - that will give you a number of bottles in one trial. Repeat and claculate average. Nothing more fancy.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook