#!/usr/bin/perl -w
# script to generate dice rolls for shadowrun using the d8 paradigm instead of
# the d6 one..
# inspired by Gurth's python prog
# john@kript.net
# version 1.2
# currently rolls 1-8, follow the comments to make it roll 0-7..
#

use strict;

@ARGV == 2 || die "Usage: $0 number of dice, 1 or 0 to roll 1-8 or 0-7\n";
unless ($ARGV[1] < 2) {
	die "Usage: $0 number of dice, 1 or 0 to roll 1-8 or 0-7\n";
}

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

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

#determine the type of dice roll required
if ($type == 1) {
	$dicetype = 8;
} else {
	$dicetype = 7;
}

# 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(8)) + $type;
	$reroll = 1;
	while ($roll % $dicetype == 0 && $roll != 0 && $reroll !=0) {
		$reroll = int(rand(8)) + $type;
		$roll = $roll + $reroll
	}
	push (@rolls, $roll);
}
 
# The sorting's not perfect, but hey..
foreach (sort @rolls) {
print "$_ ";
}
print "\n";

