Cast to CGFloat before division to force floating point division. Also use arc4random instead of random, which I've seen Xcode warn about in other projects.