Skip to content

Instantly share code, notes, and snippets.

@aybekckaya
Created June 26, 2018 00:18
Show Gist options
  • Save aybekckaya/b7f776f5e61da04dbabb4f409265c857 to your computer and use it in GitHub Desktop.
Save aybekckaya/b7f776f5e61da04dbabb4f409265c857 to your computer and use it in GitHub Desktop.
extension Int {
static func randomNumber(min:Int , max:Int)->Int {
var minimum = min
var maximum = max
if minimum < 0 { minimum = 0 }
if maximum < 0 { maximum = 0 }
if minimum == maximum { return minimum }
else if minimum > maximum { return randomNumber(min:maximum , max:minimum) }
return minimum + Int(arc4random())%(maximum - minimum)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment