Generate random numbers
  1. Create a new script with this code:

    #!/usr/bin/perl
    print "Content-Type: text/html \n\n";

    $random_number = rand(10);

    print "<p>Your Acme Auto Lucky Number from 1 to 10 is $random_number.</p>\n";

    $random_integer = int(rand(10)) + 1;

    print "<p>Your Acme Auto Lucky Integer from 1 to 10 is $random_integer.</p>\n";

    print "Click the Reload button on your browser to get a new random number.";
  2. Save the script as random.pl in the PERLSCRIPTS folder.

    Here's what the relevant lines in this script do:
  • $random_number = rand(10);

    Assigns a computer-generated random number to the scalar variable $random_number.

    Because the number 10 is inside the parenthesis:

    rand(10)

    the computer-generated number will be between 0 and 9.999999999999999.

    If you’d used the number 100—rand(100)—it would be between 0 and 99.999999999999999.

  • print "<p>Your Acme Auto Lucky Number from 1 to 10 is $random_number .</p>\n";

    Prints “Your Acme Auto Lucky Number from 1 to 10 is 8.77515995948674.

    Because it is a random number, the number on your screen will be different.