//====================================================== file = as3_2_1.c ===== //= Simulation of data transfer reliability using N block transfers = //============================================================================= //= Notes: = //= 1) This program is for assignment #2 for CAP 4800 (Simulation) for = //= Summer 2013. This is an example of a Monte Carlo simulation. = //= 2) The key input parameters are N and PR_BAD in the constants section = //=---------------------------------------------------------------------------= //= Build: bcc32 as3_2_1.c, cl as3_2_1.c, gcc as3_2_1.c -o as3_2_1 = //=---------------------------------------------------------------------------= //= Execute: as3_2_1 = //=---------------------------------------------------------------------------= //= Sample execution: = //= = //= >>> The simulation is running... = //= ============================================================= = //= == *** Results from data transfer simulation *** == = //= ============================================================= = //= = MODEL INPUT: = //= = Number of transfer iterations = 10000000 = //= = Number of blocks per transfer = 3 = //= = Probability of a block being bad = 0.100000 = //= ============================================================= = //= = MODEL OUTPUT: = //= = Success percentage = 99.898240 % = //= ============================================================= = //=---------------------------------------------------------------------------= //= History: KJC (05/21/13) - Genesis (from as3_2_1.c from summer 2011) = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() //----- Constants ------------------------------------------------------------- #define NUM_ITER 10000000 // Number of iterations to simulate #define N 5 // Number of blocks transferred per iteration #define PR_BAD 0.05 // Probability that a given block is corrupted //----- Function prototypes --------------------------------------------------- double rand_val(void); // Generate uniform RV between 0.0 and 1.0 //===== Main program ========================================================== void main(void) { int lostDataCount; // Count for lost data (none of N nlocks are good) int goodDataCount; // Count for good data (at least 1 block is good) int lostBlockCount; // Count for lost blocks double successPercent; // Success percentage int i, j; // Loop counters // Output a "running" banner printf(">>> The simulation is running... \n"); // Run the simulation for NUM_PKTS unqiue packets lostDataCount = goodDataCount = 0; for (i=0; i 0) x = x_new; else x = x_new + m; // Return a random value between 0.0 and 1.0 return((double) x / m); }