Creating an array in Swift that has random boolean values -
i working on function must create array of random boolean values , lost @ how make work inside function. on appreciated. sadly, confined rules names , how must see general structure must use, can't see how logically isn't woking.
func thirdfunction() { //var numoftrue = 0 //var numoffalse = 0 var sometrue = true var randbools = [bool] () 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) }
this works:
var array: [bool] = [] func randomizer() { var bool: bool = false num in 1...10 { let random = arc4random_uniform(2) if random == 0 { bool = false } else { bool = true } array.append(bool) } print(array) }
Comments
Post a Comment