#!/usr/local/bin/perl

$tiles_gif = glob('~eddietwo/www/xmahjongg/alltiles.gif');
$gifsicle = glob('~eddietwo/bin/gifsicle');

srand((time + $$) * (time % 7) ^ ($ENV{QUERY_STRING} * 0x1001));
$num_images = int(rand(3)) + 2;
$delay = int(rand(6)) * 15 + 65;

foreach $i (0..int(rand(3))+2) {
  do { $tile = int(rand(42)); } while $gave{$tile};
  $gave{$tile} = 1;
  $c .= " '#$tile'";
}

$| = 1;
print "Content-type: image/gif\n\n";
exec "$gifsicle -l -O2 -d$delay $tiles_gif $c";
