Code Snippet: Random Boolean

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Generate a Random Boolean[edit]

// Simulate flipping a coin and print the result
let isHeads = Bool.random()
if isHeads {
    print("Heads")
} else {
    print("Tails")
}