Wouldn't it be even more random (and randomly faster) to break out of the while loop when a winner is found? That way you are not always iterating over the entire list.
Perhaps a math/statistics expert can tell me why that is a bad idea.
Perhaps a math/statistics expert can tell me why that is a bad idea.
I didn't get it at first, either, and the Wikipedia article didn't do it for me. This explanation finally got me there: https://florian.github.io/reservoir-sampling/