Skip to content

Instantly share code, notes, and snippets.

@hujunfeng
Forked from mattt/random.swift
Last active January 2, 2016 18:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hujunfeng/a1528f9f1d6c20d6558b to your computer and use it in GitHub Desktop.
import Darwin
extension Int {
static func random() -> Int {
return Int(arc4random_uniform(UInt32(Int.max)))
}
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