#!/usr/bin/perl

# $result = die_roll;
#    Roll a standard, 6-sided die.
sub die_roll {
    return int( rand(6) ) + 1;
}

# $result = roll_dice( $number, $sides, $plus )
#   Roll the specified number of multisided dice, adding a
#   constant to the result.
#   People who play role-playing games will be used to the
#   notation 3d8+4 - they would be coded as roll_dice( 3, 8, 4 )
sub roll_dice {
    my $number = shift || 1;
    my $sides  = shift || 6;
    my $plus   = shift;

    $plus += int( rand($sides) ) while $number--;

    return $plus;
}

# $result = is_head;
#    Flip a coin, return true if it was a head.
sub is_head {
    return rand() < 0.5;
}

print roll_dice(3, 8, 4), "\n";
