UMBC CMSC201, Computer Science I, Fall 1994
Sections 0101, 0102 and Honors
Tuesday November 1, 1994
Assigned Reading: 8.2 - 8.5
Handouts (available on-line): none
Topics Covered:
- Discussion on various types of interfaces:
between hardware and software, and between operating
systems and application software. Buzzwords for the
day: "interchangeable parts for software."
- We started developing a library for generating
random numbers. Our first program
simply called the function rand() to print out
many random numbers. One problem with this program is that
the output from the program is
the same set of random numbers.
- We consulted the manual to solve this problem. First
we issued the UNIX command:
man -k random
to get a list of functions
related to the word "random". Then, we looked at the
manual pages
for the function rand() by typing:
man rand
- Using the information from the manual pages, we wrote a
second program that sets the
random seed by asking the user for a random number.
Now, the program gives different output
if the user types in a different random seed. However, if
the user types in the same seed, the program still generates
identical output.
- To fix this second problem, we want to use the system clock
to set the random seed. So, we consulted the
manual pages for the time function.
- The third version of our program
uses the time function to set the random seed. This program
prints out a different
list of random numbers every time.
In order to use the time function properly
we needed to include the header file time.h at the
beginning of the program. (We knew this from reading the
manual.)
- We then wrote the fourth version
of the program which prints a list of
random numbers between 1 and 6, so we can simulate the roll
of a six-sided die.
- Finally, we broke up our program
into several functions and used defined constants instead of
magic numbers. The output shows
the result of calling the GetRandomNumber() function
twice to simulate rolling two six-sided dice.
Last Modified:
Thu Nov 3 16:09:52 EST 1994
Richard Chang, chang@gl.umbc.edu