main.swift554 chars18 lines
In this code, we first set the number of times we want to roll the die in the rolls
constant. The sum is initialized as 0 and an empty array results
is created to store the individual rolls.
We then loop through the rolls
and generate a random number between 1 and 6 using the built-in random(in:)
function in Swift. Each result is appended to the results
array.
Finally, we loop through the results
array, add each number to the sum
variable, and print the results
array and the sum
.
gistlibby LogSnag