Last active
August 29, 2015 14:13
-
-
Save Ben-G/2677b3b59e8ef7412873 to your computer and use it in GitHub Desktop.
Swift Random Number Helper
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
/* | |
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