Rand function
#include <iostream> #include <cstdlib> using namespace std; class Dice { int val; public: void roll(); }; void Dice::roll() { val = (rand() % 6) + 1; // generate 1 through 6 cout << val << endl; } int main() { Dice one, two; one.roll(); two.roll(); one.roll(); two.roll(); one.roll(); two.roll(); return 0; }