Skip to content

Instantly share code, notes, and snippets.

@ixqbar
Created June 12, 2015 04:40
Show Gist options
  • Save ixqbar/4535ee422fe7c553c6cd to your computer and use it in GitHub Desktop.
Save ixqbar/4535ee422fe7c553c6cd to your computer and use it in GitHub Desktop.
ios之随机数
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