This nifty assignment is based on an idea advanced by Claude Shannon in 1948 [3] and subsequently popularized by A.K. Dewdney in his column in Scientific American in 1990 [1].
java -jar RandomWriter.jar 5 500 sawyer.txt result.txtfrom the command line. You can extract the two source files with a zip utility or by issuing the command
jar -xf RandomWriter.jar RandomWriter.java CharGenerator.javafrom the command line.
I have used this assignment with great success in my CS 2 classes. The assignment is nifty for at least three reasons.
The assignment touches on file input/output, string searching, the use of a dynamic linear structure (such as Java ArrayLists), and the use of randomly-generated integers. When assigned in Java, the students need to understand the portions of the Java API (java.lang.String, java.lang.StringBuffer, java.util.Random, java.util.ArrayList, java.io.FileReader, and java.io.FileWriter) that it exploits. The assignment typically takes one week.
One of the students who completed the assignment the first time I gave it used the idea behind the Random Writer to devise a new technique for synthesizing texture patterns in computer graphics applications [2]. Rather than growing a text string one character at a time, he grows texture patterns one pixel at a time.
[1] A.K. Dewdney. A potpourri of programmed prose and prosody. Scientific American, 122-TK, June 1989.