randomSample(count:)

Randomly selects the specified number of elements from this collection.

RandomSample.swift:165
func randomSample(count k: Int) -> [Element]

Parameters

k

The number of elements to randomly select.

Returns

An array of k random elements. The returned elements may be in any order. If k is greater than this collection’s count, then this method returns the full collection.

This method is equivalent to calling randomSample(k:using:), passing in the system’s default random generator.