Type Method


Returns a random Boolean value.


static func random() -> Bool

Return Value

Either true or false, randomly chosen with equal probability.


This method returns true and false with equal probability.

let flippedHeads = Bool.random()
if flippedHeads {
    print("Heads, you win!")
} else {
    print("Maybe another try?")

This method is equivalent to calling Bool.random(using:), passing in the system’s default random generator.

See Also

Creating a Random Value

static func random<T>(using: inout T) -> Bool

Returns a random Boolean value, using the given generator as a source for randomness.