Curses!

The Curses! program is a random text generator. This program generates curses such as "May a thousand flees merrily infest your red Corvette!" Curses! was originally conceived by Tom Dwyer and Margot Crichfield in 1978. This version is based on Russ Walter's description of their work.

This program works by maintaining three arrays of words/phrases; nouns, verbs, and objects. The computer randomly selects from each array and fills in the template:

May noun verb your object !

Templates are often employed to produce textual output that is human readable. However in production systems words and phrases are rarely chosen so randomly.

// -------------------------------------------------------------------------- 
// Class: Curses 
// Description: Generates a random curse by filling in the form:
//              May noun verb your object! 
// -------------------------------------------------------------------------- 
public class Curses { 

   // ----------------------------------------------------------------------- 
   // Method: main 
   // Description: Prints a random curse to standard output.
   // Inputs: String args[] // Command line arguments. IGNORED 
   // -----------------------------------------------------------------------
   public static void main( String args[ ] ) {
      // Declare and initialize data arrays.
      String nouns[ ] = { "an enraged camel", "an ancient philosopher",
                          "a cocker spaniel", "the Eiffel Tower"}; 
      String verbs[ ] = { "send a mash note to", "get inspiration from",             
                          "redecorate", "become an obsession of"}; 
      String objects[ ] = { "mother-in-law", "psychoanalyst", "rumpus room", 
                            "fern", "garage", "love letters"}; 

      // Randomly select array indices.
      int n = ( int ) Math.round( Math.random( ) * ( nouns.length - 1 ) ); 
      int v = ( int ) Math.round( Math.random( ) * ( verbs.length - 1 ) ); 
      int o = ( int ) Math.round( Math.random( ) * ( objects.length - 1 ) );

      // Display curse.
      System.out.println("May " + nouns[ n ] + verbs[ v ] + 
                         "your " + objects[ o ] + ".");
   } // end main

} // end Curses
            


Here is an applet version of the above Java application program.
(Click on it!)

The Applet Source.


References:

Walter, Russ. The Secret Guide to Computers, Volume 1: the Main Secrets. 11th edition. Russ Walter, Boston, 1984.