Difference between revisions of "Code Snippet: Random Boolean"
From Coder Merlin
(Created page with "== Generate a Random Integer == <syntaxhighlight lang="swift"> // Simulate flipping a coin and print the result let isHeads = Bool.random() if isHeads { print("Heads") } e...") |
|||
Line 1: | Line 1: | ||
== Generate a Random | == Generate a Random Boolean == | ||
<syntaxhighlight lang="swift"> | <syntaxhighlight lang="swift"> | ||
// Simulate flipping a coin and print the result | // Simulate flipping a coin and print the result |
Revision as of 00:01, 4 December 2018
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")
}