Hello,
Firstly, thanks for EPI! It’s a great book!
Now a few of comments/questions to 5.16:
-
You say, “Given a random number generator that produces values in [0, 1]” but then you use Python’s random.random() function which gives you half-open range [0.0, 1.0). Should you be saying "… that produces values in [0.0, 1.0)?
-
In the solution nonuniform_random_number_generation you prepend the cumulative probabilities with [0.0] and then you subtract 1 from bisect result. Wouldn’t be simpler skip [0.0] and then also skip the subtraction of 1?
-
I believe this solution works because it relies on two facts: a) random() gives range [0.0, 1.0) and b) you use bisect_right. It took me a little while to figure that out
Thanks!