This is the archived version of this course from the Spring 2013 semester. You might find something more recent by visitning my teaching page.
Write a Java, C++ or Python program to generate an image file with randomly-chosen points on a white background. Specifically, your program should take three integers on the command line: m, n, and k, and then create an image file that contains an m by n white canvas with k randomly-selected black dots on it.
Your program must generate its own random numbers to make the image. You must write a pseudo-random number generator to choose the points, using either the LCG or linear recurrence generator that we discussed in class. You pick the parameters of the generator so that it will produce high-quality random numbers (i.e., maximal length period, and the period should be much much much larger than the amount of numbers your program actually uses.).
You can assume that m and n will each be at most 1000. For the seed value, you may use anything that will be different every time the program is run:
/dev/urandom, the process PID, the current UNIX timestamp, whatever you like.
Basically, you will create a m by n array of values, initially all set to 0 or
false. Then you have a loop which goes k times and chooses two random integers in the appropriate ranges, and then sets that pixel (in your array) to 1 or
true. After this, you use the array to write out the contents of the image file. You should name the resulting image file random.XXX, where XXX is the file extension of a standard image format.
The image file can be in any format you like that can be opened or used in a standard Linux environment. I recommend the PPM image format: type
man ppm from Linux to find details, or read here, also this page or search for yourself. PPMs can be converted to gifs using the creatively-named
ppmtogif command so that you can actually see them. The advantage of PPM is that it's simple and text-based so creating it from your program shouldn't bee too arduous.
Submit your program according to the instructions on the submit page.