How to simulate rolling two dice (game cubes) with values 1–6 in Swift

1 Answer

0 votes
import Foundation

func rollDice() -> Int {
    Int.random(in: 1...6)   // 1–6 inclusive
}

let dice1 = rollDice()
let dice2 = rollDice()

print("Dice 1: \(dice1)")
print("Dice 2: \(dice2)")



/*
run:

Dice 1: 3
Dice 2: 3

*/

 



answered Feb 18 by avibootz

Related questions

...