// Test of random procedures to be used in CS 471 project. // **** BE WARNED! ***** // I have modified this code but have NOT tested it. // It is not my intent, but you may be in for some // surprises. // **** BE WARNED! ***** // Code has been compiled using gcc release 3.3.2 and Visual C++ #include #include #include // for log function #include // for rand functon, RAND_MAX constant using namespace std; #define HIST_SIZE 10 #define NUM_PARMS 50 #define NUM_ADDRESSES 50 #define LIST_SIZE 50 // F_RAND computes uniformly generated random variables between 0 and 1 #define F_RAND (rand()/(float)RAND_MAX) // Generate negexponential random variates with mean mean float negexp( float mean ) // Procedures called: // rand: to generate uniformly distributed random variates. // Discussion: the justification for the code can be found in // most any elementary simulation text. { // function negexp return -mean*log( F_RAND ); } // function negexp // Generate program attributes: program name, // program size, program type, program priority void task_characteristics( int max_address, float percent_interactive, int *program_name, int *program_size, int *program_type, int *program_priority ) // Procedures called: // rand: to generate uniformly distributed random variates. #define NUM_PROGS 25 #define MAX 10 #define MIN 4 { // function task_characteristics *program_name = int( NUM_PROGS*F_RAND) + 1; *program_size = int( max_address*F_RAND ) + 1; if ( F_RAND this_address ); new_address = this_address - address_diff; } else { do { random_address = max_address - this_address; address_diff = int( ( -random_address/locality )* log( F_RAND ) + 0.5 ); } while ( address_diff > random_address ); new_address = this_address + address_diff; } return new_address; } // function next_address int main() { int i; // Initialize random stream srand( 56329 ); //Simple test of function rand. int hist[ HIST_SIZE ], index, num_vars; cout << "Test of function rand" << endl; cout << "num_vars: "; cin >> num_vars; // Initialize array for ( i=0; i> num_vars; cout << "mean: "; cin >> mean; for ( i=0; i> max_address; cout << "percent_interactive: "; cin >> percent_interactive; cout << endl; cout << " Program Program Program Program" << endl; cout << " Name Size Type Priority" << endl; for ( i=1; i> max_exec_time; cout << "mean_interarrival_time: "; cin >> mean_interarrival_time; cout << endl; cout << " Program Arrival Execution" << endl; cout << " Name Time Time" << endl; for ( i=1; i> max_address; cout << "locality: "; cin >> locality; current_address = 0; cout << " Maximum permissible address: " << max_address << endl; cout << " Locality factor: " << locality << endl; cout << " Starting address: " << current_address << endl << endl; cout << " New" << endl; cout << " Ct Address" << endl; for ( i=1; i< NUM_ADDRESSES; i++ ) { current_address = next_address( max_address, current_address, locality ); cout << setw( 5 ) << i << setw( 10 ) << current_address << endl; } return 0; } // function main