My teacher gave me those code from random.cpp
But i have a question about how to code a Random() constructor in random.h
also, i feel really confuse how to code a Random( unsigned int newSeed ) in random.h too
and what does the "unsigned" for?
Thanks for help me, i would really appericate it.
![]()
Code:// System Include Files #include <cstdlib> // Required for RAND_MAX #include <iostream> // User Include Files #include "random.h" // Namespaces using namespace std; // Other Preprocessor Commands // User Defined Types // Function Prototypes // Global Variables - Don't Use! int main( void ) { Random rand; int iCtr; cout << "Generate 25 random numbers between 0 and 99..." << endl; for ( iCtr = 0; iCtr < 25; iCtr++ ) { cout.width( 3 ); cout << rand.getRandomNumber( 0, 99 ) << " "; } cout << endl << endl << endl; cout << "Generate 15 random numbers between 57 and 189..." << endl; for ( iCtr = 0; iCtr < 15; iCtr++ ) { cout.width( 4 ); cout << rand.getRandomNumber( 57, 189 ) << " "; } cout << endl << endl; unsigned int randNo; cout << "Testing 10000 random numbers between 5 and 156..." << endl; for ( iCtr = 0; iCtr < 10000; iCtr++ ) { randNo = rand.getRandomNumber( 5, 156 ); if ( ( randNo < 5 ) || ( randNo > 156 ) ) { cerr << "ERROR: " << randNo << endl; } if ( ( randNo == 5 ) || ( randNo == 156 ) ) { cout << "Boundry: " << randNo << endl; } } return EXIT_SUCCESS; } // End of file: RANDOMTEST.CPP



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.