mercredi 18 septembre 2019

Fastest way to generate a number with a geometric distribution

I would like to produce a pseudo-random number with the same distribution as the number of coin flips that are heads before the first tails.

0: p = 0.5
1: p = 0.25
2: p = 0.125
...

How can I produce a distribution like this efficiently? I've been trying to think of ways to do this without producing random bits for each flip. My current theory is to count the number of leading 0-bits in a uniformly distributed random number, but I have been unable to find a good reference or proof that this would be correct.




Aucun commentaire:

Enregistrer un commentaire