Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Last active August 29, 2015 14:13
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 Ben-G/2677b3b59e8ef7412873 to your computer and use it in GitHub Desktop.
Save Ben-G/2677b3b59e8ef7412873 to your computer and use it in GitHub Desktop.
Swift Random Number Helper
/*
Generates a random number with upper bound of provided value.
Truncates upper bound to 32-Bit values.
*/
func randomInteger(var maximum: Int) -> Int {
if maximum > Int(Int32.max) {
maximum = Int(Int32.max)
}
return Int(arc4random_uniform(
UInt32(maximum)
))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment