#include // Preprocessor Directives #include #include #include #include void main() { cout << setprecision (2) // number of digits to the right is 2 << setiosflags(ios::fixed) // display numbers in fixed form << setiosflags(ios::showpoint); // print trailing zeros // Random number generators. C++ Random Number generator generates // numbers from 1 and 32757. Other generators usually generate // numbers between 0 and 1, but not 0 and 1. // Generate a number between 0 and 32767. long inum, i ; inum = rand() ; cout << endl << inum << endl ; // Generate 10 numbers. for ( i = 0; i < 10; i++) { inum = rand() ; // %10 %52 %100 cout << inum << "\t"; } // end of for //************************************* How fast is the computer /* for ( i = 0; i < 1000000; i++) if (i % 100000 == 0) cout << endl << i ; float fnum ; for ( i = 0; i < 10; i++) { fnum = rand()/32768 ; cout << fnum << "\t" ; } // end of for //******************************************** Generating sex ************* long totf = 0, totm = 0; for ( i = 0; i < 20; i++) { inum = rand() ; if (inum % 2 == 0) cout << endl << "Male" ; else cout << endl << "Female" ; } // end of for */ } // end of main function //*************************************************************************