Originally Posted by JoBe
I don't want to just copy your solution without knowing why you did certain things and what the meaning of some of them is :!:
Bless you.
Originally Posted by JoBe
1) srand(time(NULL)); Ive read in a tutorial on this forum about it, does this make certain that the random numbers are allways different? Why are there two )'s at the end, think this was not intentional right
Originally Posted by JoBe
2) sizeof array / sizeof *array, can you give me a brief explanation why you divide these
To get the number of elements. Total array size in bytes divided by the individual element size in bytes yields the number of elements.
It is the label that the goto goes to.
REDO: array[ i ] =rand() % MAX;
for ( j = 0; j < i; ++j )
{
if ( array[ i ] == array[ j ] )
{
goto REDO;
}
Originally Posted by JoBe
4) When you use array[ j ], this is just the next number in the array wich comes after [ i ] correct and could you use something like this:
if ( array[ i ] == array[ i ] -1) because this way you are referring to the previous number in the array aswell correct
The counter j goes from zero to the current value of i.
for ( i = 0; i < sizeof array / sizeof *array; ++i )
{
REDO: array[ i ] = rand() % MAX;
for ( j = 0; j < i; ++j )
{ Just think of and example case when you're partway through. Let's say i is 40: you've already filled up array[0] to array[39] and just obtained a new candidate for array[40]. You'll want to compare array[0], array[1], array[2], ... to make sure that the current pick for array[40] isn't the same as
any of the previous ones. If array[40] is the same as array[22], you'll want to redo the random value.