5.16 Nonuniform Random Numbers - Comments (Python edition)

#1

Hello,

Firstly, thanks for EPI! It’s a great book!

Now a few of comments/questions to 5.16:

  1. 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)?

  2. 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?

  3. 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 :slight_smile:

Thanks!

0 Likes

#2

Hi @peter,

Many thanks for you comments on this problem. I think your comments contain some deep insights that I actually think for a while. Both the to suggestions are valid which I really appreciate your insights on this! Please keep letting us know if you have any suggestions and comments.

0 Likes