dice.cpp 932 B

123456789101112131415161718192021222324252627282930313233
  1. #include "dice.h"
  2. Dice::Dice()
  3. {
  4. srand(time(NULL));
  5. roll();
  6. }
  7. int Dice::roll()
  8. {
  9. // generate 6 random numbers to assign to each die
  10. for (int i = 0; i<colors; i++)
  11. {
  12. // store the previous state of the pseudo-random number generator
  13. previousSeed = rand();
  14. // store numbers generated from rand into output
  15. dice.push_back((previousSeed % 6) + 1);
  16. }
  17. return previousSeed;
  18. }
  19. void Dice::print()
  20. {
  21. fprintf (stdout, "White1 Die: %d\n", dice[white1]);
  22. fprintf (stdout, "White2 Die: %d\n", dice[white2]);
  23. fprintf (stdout, "Yellow Die: %d\n", dice[yellow]);
  24. fprintf (stdout, "Red Die: %d\n", dice[red]);
  25. fprintf (stdout, "Blue Die: %d\n", dice[blue]);
  26. fprintf (stdout, "Green Die: %d\n", dice[green]);
  27. }
  28. // non-destrucitvely add additional entropy to pseudo-random number generator
  29. void Dice::diceTropy(int entropy)
  30. {
  31. srand(previousSeed + entropy);
  32. }