Difference between revisions of "Code Snippet: Random Integers"

From Coder Merlin
Line 16: Line 16:


== Python ==
== Python ==
<syntaxhighlight lang="python">
from random import randint
print(randint(1,6))
</syntaxhighlight>
<syntaxhighlight lang="python">
from random import randint
print(randint(1,6) + randint(1,6))
</syntaxhighlight>

Revision as of 18:54, 24 December 2018

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

Generate a Random Integer[edit]

Swift[edit]

// Simulate casting a single, six-sided die and print the result
let firstDie = Int.random(in:1...6)
print(firstDie)
// Simulate casting two six-sided dice and print the sum
let firstDie = Int.random(in:1...6)
let secondDie = Int.random(in:1...6)
print(firstDie+secondDie)

Python[edit]

from random import randint
print(randint(1,6))
from random import randint
print(randint(1,6) + randint(1,6))