I have a function that generate an integer random number between two given values. This function in my app will be called only two times however, I want to avoid that it generates two same numbers or two number next to each other. How could I fix the function below to achieve that?
Example Result:
1, 1 = wrong
1, 2 = wrong
8, 7 = wrong
8, 12 = correct
1, 3 = correct
3, 0 = correct
Function:
func randomNumber(minX:UInt32, maxX:UInt32) -> Int {
let result = (arc4random() % (maxX - minX + 1)) + minX
return Int(result)
}
EDIT:
How can it be a duplicate???
I am not asking to shuffle an array but I want to generate a single Int
from two given numbers