/////////////////////////////////////////////////////////////// // rand.cpp - generate uniformily distributed random // // ver 1.0 numbers in some interval. Template class // // generates either int or double numbers. // // // // Langauge: Visual C++, ver 6.0 // // Platform: Micron Dual Pentium Pro 200, Win NT 4.0 // // Application: ELE591/791 Project #2 prototype // // Author: Jim Fawcett, CST 2-187, Syracuse Univ. // // (315) 443-3948, fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// //----< test stub >-------------------------------------------- #ifdef TEST_RAND #include #include #include "rand.h" using namespace std; void main() { cout << "\n Testing Uniform Random Number Generator " << "\n =========================================\n\n"; cout << "\n generating random integers in [1,100] " << "\n ---------------------------------------\n\n"; uniform r1(1,100); int i,j; for(i=0; i<5; i++) { for(j=0; j<20; j++) cout << setw(3) << r1.gen(); cout << '\n'; } cout << "\n\n"; cout << "\n generating random doubles in [0,1] " << "\n ---------------------------------------\n\n"; uniform r2(0.0,1.0); cout.setf(ios::floatfield,ios::fixed); cout.setf(ios::showpoint); for(i=0; i<5; i++) { for(j=0; j<7; j++) cout << setw(10) << r2.gen(); cout << '\n'; } cout << "\n\n"; cout << "\n generating random events with probability 0.75 " << "\n ------------------------------------------------\n\n"; int count = 0; for(i=0; i<1000; i++) if(event(0.75)) count++; cout << " in 1000 trials generated " << count << " events"; cout << "\n\n"; } #endif