3 ms·
Nice writeup. After reading the first paragraph, I challenged myself to come up with something and here it is: https://gist.github.com/a982f1fee5116d289323 htt
by donut 15y ago
Nice writeup. After reading the first paragraph, I challenged myself to come up with something and here it is:
https://gist.github.com/a982f1fee5116d289323 https://gist.github.com/a982f1fee5116d289323
Example run:
expected:
a 0.166666666667
b 0.333333333333
c 0.5
observed:
a 0.168
b 0.291
c 0.541
For a list of n items to choose from, it appears that pick() will terminate on the first iteration of the scary-looking while 1 loop with probability ~1/n. For n = 3, and I've run this many times, I've not seen the number of iterations exceed 30. For n = 26 it easily goes into the ~200 range at the extreme.