I'm trying to use a random number extension I created that worked in swift 2 and fails in Swift 3. Not sure why.
Here is the code.
let aRandomInt = Int.random(range:0...2)
//Extention to INT to create random number in range.
extension Int
{
static func random(range: Range<Int> ) -> Int
{
var offset = 0
if range.lowerBound < 0 // allow negative ranges
{
offset = abs(range.lowerBound)
}
let mini = UInt32(range.lowerBound + offset)
let maxi = UInt32(range.upperBound + offset)
return Int(mini + arc4random_uniform(maxi - mini)) - offset
}
}
The error I get is...
No '...' candidates produce the expected contextual result type 'Range'
This error occurs on the line that says let aRandomInt = Int.random(range:0...2)