So what I am trying to do is create a random array of 5 elements, those elements should be filled with numbers from 1 to 6 and they shall not repeat, I can't tell where my logic is wrong.
void genNumber(int vet[]){
int max, i, j, atual;
srand(time(NULL));
max = 7;
for (i=0;i<5;i++){
vet[i] = rand() % max;
while(vet[i] == 0){
vet[i] = rand() % max;
}
for(j=0;j<i;j++){
atual = vet[j];
while((vet[i] == atual)||(vet[i] == 0)){
vet[i] = rand() % max;
atual = vet[j];
}
}
}
}
Update: Fixed
void genNumber(int vet[]){
int max, i, j;
srand(time(NULL));
max = 7;
for (i=0;i<5;i++){
vet[i] = rand() % (max-1) + 1;
for(j=0;j<i;j++){
while(vet[j] == vet[i]){
vet[i] = rand() % (max-1) + 1;
j = 0;
}
}
}
}