Generating 4 unique random numbers
Hello,
To begin with, i'm new to programming so try to keep it simple :)
We're making a mastermind game at school, and i've done some of it already, but i need help with how to generate 4 unique random numbers, put into an array.
I tried it out myself, and thought this code would work, but it didnt...
Code:
#include <stdio.h>
#include <time.h>
#define ARR_SIZE 4
#define MAX 10
int main()
{
int i;
int j;
int array[ARR_SIZE];
srand(time(NULL));
for(i=0; i<ARR_SIZE; i++)
{
array[i] = rand() % MAX;
for(j=0; j<=(i-1); ++j)
{
if (array[i] != array[j])
{
continue;
}
else
{
array[i] = rand() % MAX;
}
}
}
return 0;
}
Maybe i misunderstood the "continue" command or something?