You can use the random
method in Int
struct for this.
let random:Int = Int.random(in: 1...5)
The above code will generate a random number within the closed range 1 to 5.
In closed range, both the numbers are inclusive.
let range = 1...5
print(range.contains(0)) // false
print(range.contains(3)) // true
print(range.contains(5)) // true