Last active
August 29, 2015 14:27
-
-
Save skreutzberger/bcdf15c72d9cb54ce156 to your computer and use it in GitHub Desktop.
generate random Int within range in Swift
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
// returns a random int within given range | |
func randomInt(from: Int, to: Int) -> Int { | |
let range = UInt32(to - from) | |
let rndInt = Int(arc4random_uniform(range + 1)) + from | |
return rndInt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment