Professor I. Rudowsky                                                                                    CIS 25 EW6  Simulation Assignment – Phase I                                                         Due Feb 9, 2005

 

As part of the term project you will be simulating parts of an operating system. One of the key parts of the simulation is generating the arrival of processes to be executed on the CPU.

 

(1) You will need to generate random numbers between 0 and up to but not including 1. C has a function rand() which generates a random number between 0 and RAND_MAX. (RAND_MAX is a constant in C equal to 32,767). Code genRand() so that it returns rand()/(RAND_MAX+1)  but, as both of these numbers are integer and a double should be returned, be sure to cast before you divide. Test this function well, run some small samples that you can review for accuracy.

 

(2) Another function you will need to write, genMinMax(), will be passed a minimum and maximum value (both integers >= 0) and will return an integer value that falls within those bounds. Use the formula genRand()*(max-min+1) + min  but remember that the result should be an integer between min and max so be sure to cast where needed.

Call genMinMax() 10,000 times with minimum and maximum pairs of (0,10), (1,100) and (500, 5000) and compute the minimum, maximum and average value returned from genMinMax().

Your output should be in the following format:

 

(Min,Max )Pair          

Minimum

    Maximum   

Average

(0,10)

 

 

 

(1,1000)

 

 

 

(1000,5000)

 

 

 

 

Hand in the code for genMinMax() as well as the output from the above pairs.

 

(3) Write a function genIAT() that returns an unsigned long integer based on the formula InterArrivalTime = (unsigned long) (-initVal*log(r))  where r is a random number between 0 and 1, but 0 and 1 are not valid values for r . The function genRand() already excludes 1 as a value but you will have to add code to genIAT() to exclude a value of 0 and generate another number until it is not 0 (put this in a loop as you might get two or more zeros in a row).

  1. Calculate 10,000 interarrival times and compute the minimum, maximum and average values with initVal=3000
  2. Repeat the same computation with initVal set to 1500, 500, 250, 100 and 25

Your output should be in the following format:

 

initVal      

Min IAT  

Max IAT   

Avg IAT

3000

 

 

 

1500

 

 

 

500

 

 

 

250

 

 

 

100

 

 

 

25

 

 

 

Hand in the code for genIAT() as well as the output from the above values.

 

Include your name and the assignment number in your program. Document your code, but not excessively. It should be well structured and easy to read.