#include #include // Needed for srand(), rand(), and RAND_MAX using namespace std; int main() { const int super_small = RAND_MAX / 5; // Integer division! int seed, num; cout << "The rand() function returns a random integer between 0 and " << RAND_MAX << endl; cout << "Enter an integer seed for the generator: "; cin >> seed; cout << "\n"; srand( seed ); num = rand(); if ( num < super_small ) cout << num << " is super small"; else if ( num < 2 * super_small ) cout << num << " is small"; else if ( num < 3 * super_small ) cout << num << " is midsize"; else if ( num < 4 * super_small ) cout << num << " is big"; else cout << num << " is super big"; cout << "\n\nTo get a random number in [0,1], we divide by RAND_MAX:\n"; cout << float( num ) / RAND_MAX; // Real number division! cout << "\n\n"; system( "PAUSE" ); return( 0 ); }