Created
June 12, 2015 04:40
-
-
Save ixqbar/4535ee422fe7c553c6cd to your computer and use it in GitHub Desktop.
ios之随机数
This file contains hidden or 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
func randomInRange(range: Range<Int>) -> Int { | |
let count = UInt32(range.endIndex - range.startIndex) | |
return Int(arc4random_uniform(count)) + range.startIndex | |
} | |
for _ in 0...10 { | |
print(randomInRange(1...20)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment