//Test the random number generator for randomness #include using namespace std; #include int main() { double lower; double upper; int rnum; int rsum; int total; int countr[32767]; cout << "enter a lower bound: "; cin >> lower; cout << "enter an upper bound: "; cin >> upper; cout << "enter then # of random numbers: "; cin >> total; //init counter array for (int i=lower; i<=upper; i++) { countr[i] = 0; }//end for srand(time(NULL)); //see random number generator cout << "RAND_MAX = " << RAND_MAX << endl; int startTime = time(0); //start the timer cout << "start time = " << startTime << endl; //generate random numbers in the specified range rsum = 0; for(i=1; i<=total; i++) { rnum = rand(); rnum = rnum*(upper-lower+1)/RAND_MAX + lower; //rsum = rsum + rnum; //cout << rnum << endl; countr[rnum]++; }//end for //cout << "averge of random = " << rsum/15 << endl; //cout << "average of upper and lower = " << (lower+upper-1)/2 << endl; int endTime = time(0); cout << "end time = " << endTime << endl; cout << "elapsed time = " << endTime - startTime << endl; //write counter array for (i=lower; i<=upper; i++) { cout << i << '-' << countr[i] << endl; }//end for return 0; }//end main