I would like to create a range of angles between 235 degrees and 35 degrees. This range would run 235 to 359 plus 0 to 35. I am using it in the line of code below but this of course does not work since the first integer is greater than the last integer in the range. randomAngle = Int.random(235...35). Is there a way to accomplish this?
After some thought I realized I could use an array instead of a range. I created a function that that filters out the unwanted angles and returns the filtered array. I then use array.randomElement() to get a random angle with in the range desired.
let localRange = RemoveAngles(start: 36, end: 234)
randomAngle = localRange.randomElement()!
func RemoveAngles(start: Int, end: Int) -> Array<Int> {
let fullRange: ClosedRange<Int> = 0...360
let filteredRange = fullRange.filter {
$0 < start || $0 > end
}
return filteredRange
}