Hacker News new | ask | show | jobs
by aqrit 462 days ago
> “regular” rejection sampling

I was thinking naive: mask off unwanted bits then reject any value above the limit.

It would seem like https://c-faq.com/lib/randrange.html would also move the multiply --or divide by constant-- out of the loop.

1 comments

Lemire’s algorithm rejects the fewest possible samples from the random number generator, so it’s generally the fastest. The multiplication costs very little compared to the RNG.