C++ srand seed isn't generating the proper numbers -


for program i'm working on, have function acts dice, generating random number between 1 , 6. debugging purposes, seed we're supposed use srand(333), should give same rolls. first 25 rolls of seed supposed be:

5 4 4 3 3 4 5 2 3 6 5 2 4 1 5 5 3 3 6 4 4 3 4 2 6

however, isn't happening , i've confirmed first 3 rolls 5, 5, , 4. overall program supposed simulate turn of game of pig, feel problem has originate within 1 of these 2 functions, , not main function.

int genrandint (int minroll, int maxroll) {     int randnum = minroll + (rand() % (maxroll - minroll + 1));     return randnum; } 

or

int singleturn (int holdnum) {     int diceroll = genrandint(1,6);     int score = 0;      while (score < holdnum) {         if (diceroll == 1) {             score = 0;             return score;         }         else {             score = score + diceroll;         }     }     return score; } 

if main function necessary can post it.

one of several things has happened:

  • the person produced list assuming use c++ standard library implementation + version, , you're expected using same compiler/implementation + version, you're not. code fine, need talk person made list.
  • the first 25 rolls sample, , yours may/will differ. code fine.
  • you're using rand @ different times: or rarely. if so, bug in code.

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -