function - How to output two different sets of random numbers in C++? -


so far, code:

#include <iostream> #include <time.h> #include <stdio.h>       #include <stdlib.h>   using namespace std;  int dealerroll(int dealerroll) {         srand (time(null));     (int dealercount = 1; dealercount <= 3; dealercount++)     {     dealerroll = rand()% 6+1;     cout << dealerroll << " ";     }     return dealerroll; } int playerroll(int playerroll) {          srand (time(null));     (int playercount = 1; playercount <= 3; playercount++)     {     playerroll = rand()% 6+1;     cout << playerroll << " ";     }     return playerroll; }  int main() {     int dealerroll;     int playerroll;      cout << "dealer's roll: " << endl;     dealerroll(dealerroll);     cout << endl << "your roll: " << endl;     playerroll(playerroll); system ("pause"); return 0; } 

my problem dealer , player's random (dice) roll same. output example:

dealer's roll:  1 6 3  roll:  1 6 3   

how make player's roll different dealer's this?

dealer's roll:  1 6 3  roll:  4 2 5 

it because resetting seed. needs done, unintuitively, once otherwise return same seemingly random number every time. (which have specific use cases that's you'd want do) once include line once @ top of execution, not on each successive loop through functions.

srand (time(null)); 

reference other more in-depth answer on topic.

srand() — why call once?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -