The argument type 'Range <Int>' does not match the expected type of 'Sequence' Swift3

Hi, I am getting an error after Swift3. How can I fix this error? These methods provide non-repeating random numbers.

func uniqueRandoms(_ count: Int, inRange range: Range<Int>, blacklist: [Int] = []) -> [Int] { var r = [Int](range) .filter{ !blacklist.contains($0) } .shuffle() return Array(r[0..<count]) } extension Array { func shuffle() -> Array<Element> { var newArray = self for i in 0..<newArray.count { let j = Int(arc4random_uniform(UInt32(newArray.count))) guard i != j else { continue } swap(&newArray[i], &newArray[j]) } return newArray } } 

thanks

+5
source share
2 answers

Use the lowerBound and upperBound for the range to create a sequence for the [Int] array.

 var r = [Int](range.lowerBound..<range.upperBound) 
+13
source

I suggest you use CountableRange<Int> .

0
source

Source: https://habr.com/ru/post/1257630/


All Articles