Last active
August 29, 2015 14:19
-
-
Save neilpa/a87ceefccf19f1127781 to your computer and use it in GitHub Desktop.
Randomness
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
protocol Randomizable { | |
static func random() -> Self | |
} | |
protocol IntervalRandomizable: Randomizable, Comparable { | |
static func random(interval: HalfOpenInterval<Self>) -> Self | |
static func random(interval: ClosedInterval<Self>) -> Self | |
} | |
extension CGFloat: Randomizable { | |
static func random() -> CGFloat { | |
return CGFloat(arc4random() % 100) / 100 | |
} | |
} | |
extension UIColor: Randomizable { | |
static func random() -> Self { | |
return self(red: CGFloat.random(), green: CGFloat.random(), blue: CGFloat.random(), alpha: 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment