dimanche 7 février 2016

Creating an array in Swift that has random boolean values

I am working on a function where I must create an array of random boolean values and I am lost at how to make this work inside a function. Any help on this would be appreciated. Sadly, I am confined to rules as to names and how I must do this so what you see is the general structure that I must use, but I can't see how logically this isn't woking.

func thirdFunction() {
//var numOfTrue = 0
//var numOfFalse = 0
var someTrue = true

var randBools = [Bool] ()

for num in 1...10{
    let random = arc4random_uniform(2)
    print(random)
    if (random == 0){
        someTrue = false
        randBools.append(someTrue)
    } else {
        randBools.append(someTrue)
    }
}
print (randBools)
}




Aucun commentaire:

Enregistrer un commentaire