Hi there,
I'm writing a function that fills the array with numbers from 1 - 52 with no repetitions basically my main problem is the second set of loops or the nested loops are, check to see if it is repeated and if it is it puts a new number, now i have it so it changes it but i put a statement that resets 'i' so that it rechecks the whole thing to double check theres no repetitions, and that puts it into an infinite loop. Any help will be greatly appreciated. Here is the code
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int fillDeck(int arry1[52]);
int main(){
int Deck[52];
fillDeck(Deck);
return 0;
}
int fillDeck(int arry1[52]){
srand ( time(NULL) );
for(int i = 0; i < 52; i++){
int num1 = (rand() % 52) + 1;
arry1[i] = num1;
}
for(int i = 0; i < 52; i++){
for(int j = 0; j < 52; j++){
if(arry1[i]==arry1[j]){
arry1[i] = (rand() % 52) + 1;
i = 0;
}
}
}
for(int i = 0; i < 52; i++){
printf("%d\n", arry1[i]);
}
return 0;
}