Created
September 20, 2014 09:48
-
-
Save flashspys/aebf2a41a1eaac955c25 to your computer and use it in GitHub Desktop.
simple swift random class
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
import UIKit | |
class Random { | |
class func randomInt() -> Int { | |
return Int(arc4random()); | |
} | |
class func randomIntFrom(from: Int) -> Int { | |
return from + Int(arc4random()) | |
} | |
class func randomIntTo(to: Int) -> Int { | |
return Int(arc4random()) % (to + 1) | |
} | |
class func randomInt(from: Int, to: Int) -> Int { | |
return from + Int(arc4random()) % (to - from) | |
} | |
class func randomInt(range: Range<Int>) -> Int { | |
return self.randomInt(range.startIndex, to: range.endIndex) | |
} | |
class func randomDouble(from: Double, to: Double) -> Double { | |
return drand48() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice range function