Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-226

Common Random Numbers Estimate (Seeded)

Problem

Using common random numbers, estimate P(U < p1) and P(U < p2) from the same uniforms drawn with random.Random(seed) and return [estimate1, estimate2, estimate1 - estimate2].

Return [0.0, 0.0, 0.0] for n <= 0.

Hint

Sharing uniforms couples the two estimators and reduces the variance of their difference.

Test cases

case 1
in: [0.5,0.5,10000,42]
expected: [0.499,0.499,0]
case 2
in: [0.4,0.6,10000,7]
expected: [0.4043,0.6043,-0.19999999999999996]
case 3
in: [0.2,0.9,5000,1]
expected: [0.1994,0.8958,-0.6964]
case 4
in: [0.5,0.5,0,0]
expected: [0,0,0]
Starter codePython
import random


def common_random_numbers_estimate(p1, p2, n, seed):
    # Your code here
    pass

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