Returns a random Boolean value.
This method returns true
and false
with equal probability.
let flippedHeads = Boolean.random()
if flippedHeads {
print("Heads, you win!")
} else {
print("Maybe another try?")
}
Bool.random()
uses the default random generator, Random.default
. The
call in the example above is equivalent to
Bool.random(using: &Random.default)
.
Returns: Either true
or false
, randomly chosen with equal
probability.
Declaration
static func random() -> Bool