Skip to content

Instantly share code, notes, and snippets.

@skreutzberger
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skreutzberger/bcdf15c72d9cb54ce156 to your computer and use it in GitHub Desktop.
Save skreutzberger/bcdf15c72d9cb54ce156 to your computer and use it in GitHub Desktop.
generate random Int within range in Swift
// 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