#!/usr/bin/perl

# This script generates some random xfer information
# for the students to use in the lab.

# Seed the random number generator.
srand(time % $$);

$start = 800000000;	# Just a fews days ago.  Well, quite a few. :-)

# Goofy hostnames as fakes for the statistics files.
@hosts = ("skybowl.eec.com", "azhrei.eec.com", "azhdeen.eec.com",
	  "leviathan.usda.gov", "irs.treas.gov", "ftp.principal.com",
	  "fly.bynite.com", "massmrkt.net", "223.1.1.1", "199.183.6.2"
	 );

foreach (@hosts) {
    # This next line calculates a 16-bit checksum.  Useful
    # for generating random data for each host.
    $hosts{$_} = unpack("%16a*", $_);
    print STDERR "$hosts{$_}\t$_\n";
}

foreach (1..200+rand()*40) {
    # Pick a random host and generate some data
    $idx = int(rand() * ($#hosts+1));
    $dir = rand() < .50 ? "->" : "<-";
    $bytes = int(rand() * 1000 * $hosts{ $hosts[$idx] });
    $time = int($bytes / (rand() * (1000000-28800) + 28.8) * 100) / 100;
    ($m, $h, $day, $mon, $yr) = (localtime($start))[1..5];
    $when = sprintf("%02d:%02d-%02d/%02d/%02d", $h,$m, $yr,$mon+1,$day);
    print "$hosts[$idx] $dir ftp.server.net ($when) $bytes bytes, $time secs\n";
    $start += $time + int(rand() * 1000);
}
