I've been doing code samples in SpriteKit Game Programming in Swift 2, in this Ray Wenderlich tutorial. This tutorial explains other of the game functionality very comprehensively, like the spawning of monsters, instantiation of the SKNodes
, to the point of already including verbose instructions through the comments in the Sample Project. However, the use of the random() function that I cannot really comprehend.
func random() -> Float {
return CGFloat(Float(arc4random()) / 0xFFFFFFFF)
}
func random(min min: Float, max: Float) -> Float {
return random() * (max - min) + min
}
First of all, is this merely an override of the random() function right? Isn't like the random() function returns half of the arc4random()
? And then why do have to divide it by 0xFFFFFFFF
? What does that accomplish? And is the difference of the first and second function just the range and more randomisation?