samedi 12 décembre 2015

Creating random Bool in Swift 2

So I'm needing to create a random bool value in my game, in Swift 2

It's basically, if Yes (or 1), spawn one object, if No (or 0), spawn the other.

So far, looking at this question and a similar one on here, I found this:

 let randomSequenceNumber = Int(arc4random_uniform(2))

Now it works, but it seems bias to 0 to me... like ridiculously bias...

This is how I'm then using the value:

if(randomSequenceNumber == 0)
    //spawn object A
else
    //spawn object B

Is there a better way to implement this using a random bool value? That isn't bias to a certain value?




Aucun commentaire:

Enregistrer un commentaire