#!/usr/bin/perl -w
# script to generate dice rolls for shadowrun 
# inspired by Gurth's Python script
# john@kript.net 
# version 1

use strict;

@ARGV == 1 || die "Usage: $0 number of dice to roll\n";


# Declare the variables
my ($dice, $count, $roll, $reroll);
my (@rolls);

#Initialise the variables
$dice = $ARGV[0];
$count = 0;

# generate a dice roll until the number of dice specified has been met,
#  and append it to the @rolls array
while ($count < $dice) {
	$count++;
	$roll = int(rand(6)) + 1;
	$reroll = 1;
	while ($roll % 6 == 0 && $roll != 0 && $reroll !=0) {
		$reroll = int(rand(6)) + 1;
		$roll = $roll + $reroll
	}
	push (@rolls, $roll);
}
 
# sorting's not perfect, but hey, its free! 
foreach (sort @rolls) {
print "$_ ";
}
print "\n";
