The current test for the Fisher-Yates Shuffle returns a different list of shuffled indexes for each iteration of the map method because the same random number generator variable is reused for all calls on the shuffled() method. This does not invalidate the test, but makes it less obvious what the count argument does in the shuffled() method. When implementing myself, I was initially under the impression that the count somehow influenced the returned result, which was puzzling. Moreover, I was contrasting this implementation with the Hummingbird implementation of this method, which always returns the fully shuffled list. I was expecting the count to simply help me return a subset of the list, but since all the lists were different on each iterations in the Swift test, I got confused for a little bit until I realized that the issue was simply that the rng was being reused for each call.
The text accompanying this Fisher-Yates Shuffle section mentions:
Its implementation affords efficiently generating only the number of fragments needed for a given part, rather than shuffling all fragment indexes and then taking a subset.
I propose the following small change which (a) makes explicit the value of the count argument in the method, and (b) showcases what the paragraph above describing the choice of algorithm mentions and brings it more in line with its test:
The current test for the Fisher-Yates Shuffle returns a different list of shuffled indexes for each iteration of the map method because the same random number generator variable is reused for all calls on the
shuffled()
method. This does not invalidate the test, but makes it less obvious what thecount
argument does in theshuffled()
method. When implementing myself, I was initially under the impression that the count somehow influenced the returned result, which was puzzling. Moreover, I was contrasting this implementation with the Hummingbird implementation of this method, which always returns the fully shuffled list. I was expecting the count to simply help me return a subset of the list, but since all the lists were different on each iterations in the Swift test, I got confused for a little bit until I realized that the issue was simply that the rng was being reused for each call.Current test
Proposed new test
The text accompanying this Fisher-Yates Shuffle section mentions:
I propose the following small change which (a) makes explicit the value of the
count
argument in the method, and (b) showcases what the paragraph above describing the choice of algorithm mentions and brings it more in line with its test:I'm happy to open the PR on the paper as well as the URKit tests if this is a welcome change.