Quote:
they must not repeat
This make that it is not random,
it is shuffle. Just like with cards.
The problem with your program is that it degenerate as it pick values, it is more and more difficult to pick unused ones.
There is another technique to shuffle values.
Say you want to shuffle 52 cards.
- make a list of the 52 values in an array.
- pick a random position between 0 and 51 and swap that position with position 0.
- pick a random position between 1 and 51 and swap that position with position 1.
- pick a random position between 2 and 51 and swap that position with position 2.
- repeat until enough cards are shuffled.
- read the array, it is your result.
Advantage, it don't degenerate, for 52 cards, you need 51 uses of random function.