J
James Kuyper
Keith Thompson:
*WHOOSH*
Let's go back to Bill's original post (emphasis mine):
If you just move the rand() inside the loop, there's no guarantee that all
of the numbers will actually be different.[/QUOTE]
True - but out of what range does he want them to be randomly selected?
If he wants them to range from 0 to RAND_MAX, calls to rand() followed
by rejection of duplicates is probably the best approach, at least if
the number of values needed is much smaller than RAND_MAX.
That doesn't do the same thing. If corrected, Bill's program
would set each element to a random integer from 0 to RAND_MAX.
Your suggestion would set each element to a value from 1 to n with
no repetitions.
*WHOOSH*
Let's go back to Bill's original post (emphasis mine):
If you just move the rand() inside the loop, there's no guarantee that all
of the numbers will actually be different.[/QUOTE]
True - but out of what range does he want them to be randomly selected?
If he wants them to range from 0 to RAND_MAX, calls to rand() followed
by rejection of duplicates is probably the best approach, at least if
the number of values needed is much smaller than RAND_MAX.