Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
13 lines (11 sloc) 300 Bytes
extension Set {
public func sample() -> Set.Element? {
if count > 0 {
let offset = Int(arc4random()) % count
let nIndex = index(startIndex, offsetBy: offset)//index.index(startIndex, offsetBy: offset)
return self[nIndex]
} else {
return nil
}
}
}