randomizing error. help please

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void randomize_deck()
{
      int rand1, rand2;
      card holder;
      card holder2;
      srand ( time(NULL) );              /* initialize random seed: */
  
      for (int j=1; j <1000;j++)         // Swaps a random pair of cards 1000 times
      {   rand1 = rand() % 52;
          rand2 = rand() % 52;
          holder.str_rank = deck[rand1].str_rank;      
          deck[rand1].str_rank = deck[rand2].str_rank;
          deck[rand2].str_rank = holder.str_rank;
      }
} 

whats wrong? it is not randomizig properly?
Only call srand once at the beginning of your program.
Also you're only swapping str_rank. Why not just swap the entire card?

1
2
3
          holder = deck[rand1];      
          deck[rand1] = deck[rand2];
          deck[rand2] = holder;
Topic archived. No new replies allowed.