D-Programming-Language/phobos — pull request #1533 by WebDrake (2013-08-29 17:20:48+00:00)
Title: Fix Issue 10322 - ensure that RandomSample is initialized before using

This set of patches fixes a problem where the public methods .index() or .popFront() might be called without the first value of the sample having been determined, which would then cause spurious results. The check currently performed in .front has been extended to these functions.

The patchset in fact contains two distinct fixes to the problem. The first is a minimal fix which preserves the general character of the previous code, while eliminating the unnecessary boolean variable _first and basing the check for initialization on the internal variable _Vprime. The second revises this fix, deleting the boolean _algorithmA and replacing it with a function delegate which determines which of the algorithms to use. This latter solution results in a small speed-up for sampling where Algorithm A is the method chosen, as it reduces the number of if() checks required.

Finally, the .index() method has been made a property, which I take to be an oversight in the original design. :-)