Created
January 4, 2017 08:01
-
-
Save suatkarakusoglu/726c831a92a0625a9144bcaeabaac520 to your computer and use it in GitHub Desktop.
RandomInt generation inside range.
This file contains 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
extension RandomAccessCollection{ | |
func randomInt() -> Int? { | |
guard let startNumber = self.first as? Int else { return nil } | |
guard let endNumber = self.last as? Int else { return nil } | |
let rangeNumber = endNumber - startNumber | |
let random = Int(arc4random_uniform(UInt32(rangeNumber))) + startNumber; | |
return random | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment