D-Programming-Language/phobos — pull request #1342 by WebDrake (2013-06-09 13:35:06+00:00)
Title: Issue 10269 - RandomSample should use popFrontExactly, not popFrontN ...

... when skipping across input range. This results in a small speedup of RandomSample.popFront(), larger in the case of input where popFrontN() and popFrontExactly() will be of O(n) rather than O(1).

This small tweak has been accompanied by a couple of extra checks to ensure that users do not request more sample points than are available in the input, which could otherwise be the source of exceptions.

There exists one remaining case where RandomSample may fail: if it is given an InputRange without the .length property, and the user indicates that the total number of items available is greater than what the InputRange actually contains. In this case an exception is thrown from std.array.popFront() line 450, "Attempting to popFront() past the end of an array", or from std.array.front() line 624, "Attempting to fetch the front of an
empty array."