Homework 2 CEN 4010 Spring 2017
A common use of random numbers is to simulate events using a program, rather than going through the
time and expense of constructing a real-life experiment. For example, statistical theory tells us that the
probability of having a tossed coin turn up heads is 0.5. Similarly, there is a 50 percent probability of
having a single tossed coin turn up tails. Using these probabilities, we would expect a single coin that is
tossed 1000 times to turn up heads 500 times and tails 500 times. In practice, however, this is never
exactly realized for a single experiment consisting of 1000 tosses. Instead of actually tossing a coin 1000
times, however, we can use a random number generator to simulate these tosses.
In particular, we could use any random number generator function that is available in the market or
develop our own random number generator function. Lets assume we have developed a function rand
() that generates random numbers between 0 and 0.99. Using this normalized random number, we can
simulate coin tosses for number of times until we get the desired output.
We can use the following algorithm to develop our program:
Initialize the heads count to zero Initialize the tail count to zero.
For 1000 times get a random number between 0 and 1 if the random number is greater than 0.5
consider this as a head and add one to the heads count else consider this as a tail and add one to the
tails count end if enf
for calculate the percentage of heads as the number of heads divided by 1000 X 100% calculate the
percentage of tails as the number of tails divided by 1000 X 100%
print the percentage of heads and tails obtained
Design a software system that generates a random number (or calls random number generator
function), then performs coin toss simulation.
Turn In:
1) Use the format that is posted in Falcon On-line (D2L) (under Dropbox)
2) Analysis and design documents
a. Context Diagram
b. Data Flow Diagram
c. Data Dictionary
d. Process Specification
e. Structure chart
f. Module specification
g. Implementation
Due: April 4, 2017 (before midnight).