vendredi 1 avril 2016

How to generate 2 different random arrays of numbers using a C'tor in c++?

I am trying to create to different objects from the class 'NumSet'. NumSet Player1,player2; It generates 1 array properly - with random numbers. But the second one is copied just the same. The array of player one is equal to the array of player2. How to solve this ? Thanks.

NumSet::NumSet()
{
    srand(time(0));
    for (int i = 0; i < C_NUM; i++) {//Generate 2 random arrays.
        n_cards[i] = (rand() % 10) + 1;
    }
}

For example player1 will looks like that: {3,4,5,2,5} which is good (initialized with random numbers). The problem I dont know how to solve is that player2 will be exactly the same: {3,4,5,2,5}




Aucun commentaire:

Enregistrer un commentaire