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)
}
let someBool = arc4random_uniform(2) == 1and append someBoolarc4random_uniform(2)returns a number between 0 and <2. For example 0.1, 1.45, 1.999. Your code checks to see if it's exactly 0.0000. Which is VERY unlikely and not very random. However, should it ever happen, it also setssomeTruetofalse, so all subsequent randBools will also be false.Booland now you're saying you need to work with0and1? Kinda confusing :).