Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-216

Exponential Variate Mean (Seeded)

Problem

Estimate the mean of an Exponential(lam) distribution by inverse-transform simulation. Draw n uniforms from random.Random(seed), transform each with -log(1 - U) / lam, and return the average. Return 0.0 for invalid inputs.

Hint

The inverse CDF of the exponential is -log(1 - U) / lam.

Test cases

case 1
in: [1,10000,42]
expected: 0.9995207951445273
case 2
in: [2,10000,7]
expected: 0.49812329121720605
case 3
in: [0.5,5000,123]
expected: 1.9953393953396754
case 4
in: [1,0,5]
expected: 0
Starter codePython
import math
import random


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

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