Chance of a conditional occurring in Swift: Xcode -


i quite new xcode , swift sorry if bad description. there way there chance of conditional occurring instead of happening 100% of time when conditions met, happens 50% of time when conditions met? example,

if (x = 10) { occur 50% of time or has chance of happening }

all feedback appreciated!

you can use arc4random_uniform create read computed property generate random number , return boolean value based on result. if number generated equal 1 return true, if equal 0 return false. combined if conditional can execute code inside brackets when random number equal 1 (true).

let randomzeroone = arc4random_uniform(2)  if randomzeroone == 1 {     println(randomzeroone) // } else if randomzeroone == 0 {     println(randomzeroone) // }  println(randomzeroone == 1 ? "this" : "that") 

using approach can end example bellow:

var truefalse: bool {     return arc4random_uniform(2) == 1 }  println(truefalse) println(truefalse) println(truefalse) println(truefalse) println(truefalse) println(truefalse) println(truefalse) println(truefalse) println(truefalse)  if truefalse {     // 50% odds } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -