Piet Souris wrote:
Now, if we draw a random number, say 10, then we check if array[10] == 0. If not, then that indicates that 10 is already drawn. If so, we keep trying a new random number i until array[i] == 0.
If that succeeds, we put a 1 in array[i], so that we know it has been drawn.
Why not just use a boolean array then?
There are far more elegant ways, but this one is simple enough.
If you use a boolean array, this solution is not bad.
If you don't want to use a boolean array, you can just move a number that has been "drawn" to the "end" of the array, where the "end" is always moved down towards 0 after a number is drawn and swapped. You'd also adjust the range from which you pick the next number to draw.