Skip to content

Instantly share code, notes, and snippets.

@bennokress
Last active June 25, 2017 11:26
Show Gist options
  • Save bennokress/8592e5a7d6b11f31e5eaf9998348035e to your computer and use it in GitHub Desktop.
Save bennokress/8592e5a7d6b11f31e5eaf9998348035e to your computer and use it in GitHub Desktop.
Extensions for Swift's Int Type
extension Int {
static func random(between min: Int, and max: Int) -> Int {
return min + Int(arc4random_uniform(UInt32(max - min + 1)))
}
/// Returns the digits in self
var digits: Int {
return self.abs < 10 ? 1 : 1 + (self / 10).digits
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment