#C14564. Dice Roll Simulation and Probability Computation

    ID: 44227 Type: Default 1000ms 256MiB

Dice Roll Simulation and Probability Computation

Dice Roll Simulation and Probability Computation

In this problem, you are required to simulate rolling two standard six-sided dice a given number of times and compute the probability of obtaining a sum of 7. Specifically, you need to:

  • Simulate dice rolls using a pseudo‐random number generator. Important: For reproducibility, initialize the random seed to 0.
  • Count the frequency of each possible sum (from 2 to 12).
  • Calculate the simulated probability of obtaining a sum of 7.

    Note that the theoretical probability is given by \[ P(7)=\frac{6}{36}=\frac{1}{6}\approx0.16667, \] since there are 6 combinations out of 36 total outcomes that yield a sum of 7.
  • Output the simulated probability, the theoretical probability, and their absolute difference. Format all floating point numbers to 5 decimal places.

Example:
If the number of rolls is 10000, a sample output might be:
Simulated Probability of rolling a sum of 7: 0.16750 Theoretical Probability of rolling a sum of 7: 0.16667 Difference: 0.00083

inputFormat

The input consists of a single integer n (n > 0) which denotes the number of times the two dice are rolled. The input is given via standard input (stdin).

outputFormat

The output should contain exactly three lines printed to standard output (stdout):

  • The first line prints the simulated probability of rolling a sum of 7 in the format:
    Simulated Probability of rolling a sum of 7: X
  • The second line prints the theoretical probability (which is always 1/6) in the format:
    Theoretical Probability of rolling a sum of 7: Y
  • The third line prints the absolute difference between the simulated and theoretical probabilities in the format:
    Difference: Z
All probabilities should be printed as floating point numbers with 5 decimal places.## sample
10000
Simulated Probability of rolling a sum of 7: 0.16750

Theoretical Probability of rolling a sum of 7: 0.16667 Difference: 0.00083

</p>