Now we have randomSample method for collections to get multiple random elements of a specific number with orders shuffled. This behavior should make it easy to make a shuffle method, which don't have to take any parameters (or a generator, if needed) to shuffle the collection. Inside the shuffle method, we just have to call randomSample(count: self.count) and it should work as expected:
let aCollection = [1, 2, 3, 4, 5]
let shuffled = aCollection.shuffled()
// ↑ which should be identical with `aCollection.randomSample(count: aCollection.count)`
Now we have
randomSample
method for collections to get multiple random elements of a specific number with orders shuffled. This behavior should make it easy to make a shuffle method, which don't have to take any parameters (or a generator, if needed) to shuffle the collection. Inside the shuffle method, we just have to callrandomSample(count: self.count)
and it should work as expected: