3 ms·
You are not taking the index of the element that you are currently sampling into consideration. Suppose that the sample size is 1 and you are getting the secon
by danieldk 12y ago
You are not taking the index of the element that you are currently sampling into consideration.
Suppose that the sample size is 1 and you are getting the second item (index 1). You will call rand(1), which has 0 as the only possible outcome. So, you will always replace the first item (index 0). Whereas if you would call rand(2) (possible outcomes: 0 and 1), you replace the item in the sample with probability .5 (assuming that the random number generator is uniform).
- timr 12y agoD'oh. Yes, I think you're right. That'll teach me to try to mentally debug code at 2AM! I'll fix the code and publish a new gem a bit later today. Thanks!