I'm trying to randomize 4 different numbers in C and trying the next code:
{
int num1 = 0, num2 = 0, num3 = 0, num4 = 0;
int i = 0;
while (num1 == num2 && num1 == num3 && num1 == num4 && num2 == num3 && num2 == num4 && num3 == num4 && num3 == num2)
{
num1 = rand() % 7;
num2 = rand() % 7;
num3 = rand() % 7;
num4 = rand() % 7;
}
printf("%d %d %d %d\n", num1, num2, num3, num4);
}
The code suppose to check if the numbers are not equal and if they are equal, it needs to generate new numbers until they are all distinct. But for some reason, it's not working well and even right numbers it puts them as wrong and it becomes and endless loop.
What am I missing?