Skip to content

Instantly share code, notes, and snippets.

@flashspys
Created September 20, 2014 09:48
Show Gist options
  • Save flashspys/aebf2a41a1eaac955c25 to your computer and use it in GitHub Desktop.
Save flashspys/aebf2a41a1eaac955c25 to your computer and use it in GitHub Desktop.
simple swift random class
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()
}
}
@iCarambaa
Copy link

nice range function

@flashspys
Copy link
Author

thx 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment