Random Numbers with no Repitition
I'm trying to get a an array of 10 numbers filled with random numbers 0-9 with no repetition. I have the following code:
Code:
{
int i, j;
int used[10];
int temp;
int count = 0;
int check;
srand(time(NULL));
used[0] = rand() % 10;
for(i = 1; i < 10; i++)
{
check = 0;
do{
temp = rand() % 10;
for(j = 0; j < i; j++)
{
if(temp == used[j])
check = 1;
}
if(check != 1)
{
used[i] = temp;
check = 0;
}
}while(check != 0);
}
I include stdio.h, stdlib.h, string.h, time.h.
When I run this, I get an infinite loop. When I manage to fix the infinite loop, I still get repetition.
Anyone see how I can fix these problems??