Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-094

Monte Carlo Estimate (Seeded)

Problem

Estimate P(U1 + U2 < 1) for independent Uniform(0, 1) draws by simulation, where the exact answer is 0.5.

Draw n pairs of values using random.Random(seed), count the pairs whose sum is below 1, and return the observed fraction. Return 0.0 for n <= 0.

Hint

Use a private random.Random(seed) instance for reproducibility.

Test cases

case 1
in: [10000,42]
expected: 0.5
case 2
in: [10000,7]
expected: 0.5072
case 3
in: [1,0]
expected: 0
case 4
in: [0,5]
expected: 0
Starter codePython
import random


def simulation_estimate_seeded(n, seed):
    # Your code here
    pass

4 test cases · run your code against them in the editor