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

1 Answer

0 votes
function rollDice(): int {
    return random_int(1, 6);   // 1–6 inclusive
}

$dice1 = rollDice();
$dice2 = rollDice();

echo "Dice 1: $dice1\n";
echo "Dice 2: $dice2\n";




/*
run:

Dice 1: 6
Dice 2: 4

*/

 



answered Feb 18 by avibootz

Related questions

...