Here is a general function that I just wrote quickly to get a random number within a range.
func randomBetweenNumbers(firstNum: CGFloat, secondNum: CGFloat) -> CGFloat{ return CGFloat(arc4random()) / CGFloat(UINT32_MAX) * abs(firstNum - secondNum) + min(firstNum, secondNum) }
It takes a random number, finds the remainder of this number divided by the difference between the two parameters, and then adds a smaller number. This ensures that a random number must be between two numbers.
Disclaimer: I have not tested this yet.
EDIT : Now this function does what you want.
source share