#!/usr/bin/perl

my @tickets = (1..4000);
my $w = 80;
my $h = 50;
srand(time);
fisher_yates_shuffle(\@tickets);

print << "EOH";
<html>
	<head><title>Generated Llama Grid</title>
	<style>
		table, tr, td,th {border:1px black solid;border-collapse:collapse;padding:2px;}
		td{text-align:right}
	</style>
	</head>
<body>
	<table>
	<tr><th>&nbsp;</th>
EOH

foreach my $j(1..$w) {
	print "<th>$j</th>";
}
print "</tr>\n";
	
foreach my $i(0..$h-1) {
	print "\t<tr><th>".($i+1)."</th>";
	foreach my $j(0..$w-1) {
		my $index = $tickets[($i * $w) + $j];
		my $num = $tickets[$index];
		print "<td>$num</td>";
	}
	print "</tr>\n";
}
print "</table>\n</body></html>";


sub fisher_yates_shuffle {
    my $array = shift;
    my $i;
    for ($i = @$array; --$i; ) {
        my $j = int rand ($i+1);
        next if $i == $j;
        @$array[$i,$j] = @$array[$j,$i];
    }
}
