123456789101112131415161718192021222324252627282930313233 |
- #include "dice.h"
- Dice::Dice()
- {
- srand(time(NULL));
- roll();
- }
- int Dice::roll()
- {
- // generate 6 random numbers to assign to each die
- for (int i = 0; i<colors; i++)
- {
- // store the previous state of the pseudo-random number generator
- previousSeed = rand();
- // store numbers generated from rand into output
- dice.push_back((previousSeed % 6) + 1);
- }
- return previousSeed;
- }
- void Dice::print()
- {
- fprintf (stdout, "White1 Die: %d\n", dice[white1]);
- fprintf (stdout, "White2 Die: %d\n", dice[white2]);
- fprintf (stdout, "Yellow Die: %d\n", dice[yellow]);
- fprintf (stdout, "Red Die: %d\n", dice[red]);
- fprintf (stdout, "Blue Die: %d\n", dice[blue]);
- fprintf (stdout, "Green Die: %d\n", dice[green]);
- }
- // non-destrucitvely add additional entropy to pseudo-random number generator
- void Dice::diceTropy(int entropy)
- {
- srand(previousSeed + entropy);
- }
|