Skip to content

Instantly share code, notes, and snippets.

@endodoug
Created November 4, 2016 02:37
Show Gist options
  • Save endodoug/0e2f2b8dc5b2e95e459b16432a02ce49 to your computer and use it in GitHub Desktop.
Save endodoug/0e2f2b8dc5b2e95e459b16432a02ce49 to your computer and use it in GitHub Desktop.
Random Numbers - Swift 3
func randomFloat(from from:CGFloat, to:CGFloat) -> CGFloat {
let rand:CGFloat = CGFloat(Float(arc4random()) / 0xFFFFFFFF)
return (rand) * (to - from) + from
}
func randomInt(n: Int) -> Int {
return Int(arc4random_uniform(UInt32(n)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment