Project 50: Range of Four Dice

In the example of 4 dice above, the range would be 4.  The range is defined by the maximum value - minimum value.  Since the highest value is 5 and the lowest value is 1, the range would be 4.


Project 50:  Variable 'r' has been initialized.

r must be a value between 0 and 5.

Simulate MANY trials (at least 100,000) of rolling four fair dice.  Estimate the probability that the range is 'r'.

Task: Appropriately assign the value of 'proportion' to represent the probability that the range of four dice is r.


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