lundi 28 décembre 2015

Why use Float(arc4random()) / 0xFFFFFFFF instead of drand()

I'm new to Swift and just saw this code used to generate a random angle degree in a tutorial.

func random() ->CGFloat{
    return CGFloat(Float(arc4random()) / 0xFFFFFFFF)
}
func random(#min: CGFloat, max:CGFloat) ->CGFloat{
    return random()*(max-min)+min
}

I'm wondering is the line return CGFloat(Float(arc4random()) / 0xFFFFFFFF) generates a random float number between 0 and 1.0? Then why cannot just use drand()? Any difference between the two functions? Thanks!




Aucun commentaire:

Enregistrer un commentaire