Last active
March 12, 2017 01:08
-
-
Save efremidze/2a491e1bb5b140c41e7b1194c63dc5b3 to your computer and use it in GitHub Desktop.
random number from range
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
extension UInt32 { | |
static func random(_ range: Range<UInt32>) -> UInt32 { | |
return arc4random_uniform(range.upperBound - range.lowerBound) + range.lowerBound | |
} | |
} | |
extension CGFloat { | |
static func random(_ range: Range<CGFloat>) -> CGFloat { | |
return CGFloat(arc4random()) / CGFloat(UINT32_MAX) * (range.upperBound - range.lowerBound) + range.lowerBound | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment