Arrrays, Loops, and Randomization
I have an int arrary of 10 -
int array[10]
by using #include <time.h> to be able to srnd using time for true varience like:
srand( (unsigned)time( NULL ) );
j = (int) 10 * rand() / (RAND_MAX + 1.0);
I want to be able to somehow create a loop (probably by using another array as well) that will put the numbers 1-10 in the array indices but in a way that all the numbers 1-10 are used and none are repeated.
I don't know if I am even on the right track of how I am going about this.. but I was thinking using another array filled with the numbers 1-10 and then somehow when I get j turn j's indice into a 0 and then my check for continuing the loop would be if all the indces of array2 are used and to only use the indice of array[j] if it is not 0.
so check for the loop would be something like...
for (i = 10, c = 0; i < 10 ; i++)
{
c = c + array[i];
}
if (c == 0)
/* stop loop */
else
/* loop continues */
and then in a nested loop maybe? something like..
{
srand( (unsigned)time( NULL ) );
j = (int) 10 * rand() / (RAND_MAX + 1.0)
if (array2[j] == 0);
else
{
array2[j] = 0;
array1[i] = j;
i++;
}
}
Any suggestions? thoughts? comments? How do I do this?