#!/usr/bin/perl

# Create the error message logfile.

# This script generates a list of all possible error
# messages and then loops around 100 times randomly
# picking one to print.  There is a 30% chance that
# the message will be a warning instead of an error.

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

# Only generate 15 different error messages
$maxerr = 15;
@ErrorMsg = ();
foreach (1..$maxerr) {
    $! = $_;
    push(@ErrorMsg, "$!");
}

open(LOG, "> logfile") or die "Can't create logfile: $!\n";
# Create a logfile with 100 messages in it.
foreach $i (1..100) {
    # Choose a random error message.
    $r = rand() * $maxerr;

    # 30% chance of "Warning" instead of "Error".
    print LOG rand() < .30 ? "Warning" : "Error", ": $ErrorMsg[ $r ]\n";
}
close(LOG);
