Project 25: Expected Value Simulation

Expected Value

 

Suppose there is a game of chance played with rules listed below:

 

A person pays $10 to play the game.

 

A person rolls a six-sided fair die.  If the result is 6, the person wins a prize of $20. 

 

If a 6 is NOT rolled, the person flips a coin.  If the result is heads, the person wins a prize of $15.  If the result is tails, the person wins nothing.

 

Note: If a person pays $10 to play and wins a prize of $20, the profit of the game is $20-$10 = $10.

 

We want to figure out if playing this game is worth the risk.  One metric used to determine this is to determine how much profit a person would win on average by playing this game MANY times.  There is a way to calculate this value theoretically, but it is easier to simulate.

 

Project 25: Simulate MANY trials to estimate the mean amount (expected value) of profit earned from playing this game.  The more trials you simulate, the closer your estimated value would be to the true value of the mean.  


Task: Assign the variable called 'expected' to be the appropriate average.


Note: There are two working randomization methods available to use.


random() returns a random number from [0,1)


Example: r = random();  //r holds a value between 0 and 1 (not including 1).


randomInt(lower, upper) returns a random integer between lower and upper inclusive.


Example: i = randomInt(2,7); //i holds one of the values: 2, 3, 4, 5, 6, 7 and they are all equally likely

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0