Created
January 13, 2017 18:12
-
-
Save abarrak/85697103b1a7a6d1579fec3e4f2a72d0 to your computer and use it in GitHub Desktop.
Ruby's sample in swift lang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ArrayExtension.swift | |
| // Brings sample() to swift | |
| // | |
| // Created by Abdullah on 10/3/16. | |
| // | |
| import Foundation | |
| extension Array { | |
| func sample() -> Element { | |
| srandom(UInt32(time(nil))) | |
| return self[random() % self.count] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment