//dietest.cpp #include //for cout #include //for setw #include //for rand,srand #include //for time using namespace std; class Die { public: Die(int n=6) //6 is the default value for n {number_of_sides=n;} int roll() { return rand()%number_of_sides + 1 ;} private: int number_of_sides; }; //end class Die int main() { Die d; for(int k=1 ; k<=20 ; k++) cout << setw(3) << d.roll(); cout << "\nNow for an octohedron" << '\n'; Die octohedron(8); for(int m=1 ; m<=20 ; m++) cout << setw(3) << octohedron.roll(); //to manually seed rand unsigned seed; int h, count,j; long t; for (count=1; count<=2; count++) { cout << "\nWith a fixed seed.\n"; seed=473; srand(seed); for(h=1 ; h<=20 ; h++) cout << setw(3) << d.roll(); } //to randomize the seed for (count=1; count<=2; count++) { cout << "\nWith time in secs used" << " as a seed.\n"; t=time(0); cout << t << '\n'; srand(t); //this should only be called once in a program for(h=1 ; h<=20 ; h++) cout << setw(3) << d.roll(); //waste time for (j=1; j<100000000; j++); } return 0; }