Dice Rolling Simulator : rand « Math « PHP






Dice Rolling Simulator

 
<?php
function roll_dice($number, $sides, $values = false) {
    $dice = array();
    for ($i = 0; $i < $number; $i++) {
        $dice[] = rand(1, $sides);
    }

    if ($values) {
        return $dice;
    } else {
        return array_sum($dice);
    }
}
$roll_3d6 = roll_dice(3, 6);
echo "<pre>Dice roll = {$roll_3d6}\n";

$rm_stats = roll_dice(10, 100, true);
print_r($rm_stats);
echo '</pre>';
?>
  
  








Related examples in the same category

1.Generate random numbers (integer values) between 0 and MAX_RAND by calling rand() or mt_rand() without any arguments
2.int rand ( [int min, int max] ) returns random numbers
3.Random Images
4.Random Numbers