Last active
August 26, 2019 15:37
-
-
Save mattt/f2ee2eed3570d1a9d644 to your computer and use it in GitHub Desktop.
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
import Darwin | |
extension Int { | |
static func random() -> Int { | |
return Int(arc4random()) | |
} | |
static func random(range: Range<Int>) -> Int { | |
return Int(arc4random_uniform(UInt32(range.endIndex - range.startIndex))) + range.startIndex | |
} | |
} | |
extension Double { | |
static func random() -> Double { | |
return drand48() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note iLast can be left out in favor of
..<count
.Same in
Int.random(i..<count)
.Also note
[T]
is deprecated in favor of[Element]
For sets