All problems
Inverse Transform Exponential Sample
Problem
To sample an exponential with rate lambda from u uniform on (0, 1), apply x = -ln(1 - u) / lambda.
Given u and the rate, return the transformed sample.
Hint
Invert the exponential CDF.
Test cases
case 1
in: [0.5,1]
expected: 0.6931471805599453
case 2
in: [0.1,2]
expected: 0.05268025782891314
case 3
in: [0.9,0.5]
expected: 4.605170185988092
Starter codePython
def inverse_transform_exponential_sample(u, rate):
# Your code here
pass3 test cases · run your code against them in the editor