The idea is that if you have a list of 49 numbers, to select the first 6 numbers at random without replacement, you do a partial shuffle such that the first 6 numbers out of the 49 are done with the shuffling (or you can completely shuffle all 49, that's fine too, just extra work). Then, you just need to select these first 6 numbers, ignoring the remaining 43, and you're done. Doing this right is slightly tricky though: Salem's post #44 demonstrates a somewhat different shuffling approach that arguably does too much and yet risks doing too little: you need to shuffle the entire list, and yet if you don't have enough iterations, you won't be shuffling enough.Originally Posted bywolly

A correct and efficient approach is as given in the Knuth/Fisher-Yates shuffle: you repeatedly randomly select an item from the "unshuffled" portion of the list and swap it into position; the item that was swapped out of position now forms part of the "unshuffled" portion of the list, whereas the item that was swapped into position joins the "shuffled" portion of the list. This is basically akin to having a bag of items and taking them one by one at random to join your sequential hand of items. Therefore, you can do a partial shuffle with just 6 iterations with one swap each and you're done, needing only 6 random numbers to be generated.

You might find it easier to implement another approach: build your list of random numbers by generating random numbers in the range and checking to see if it already exists if your list of generated numbers. If it doesn't, you add it to the list, otherwise you regenerate the random number. This approach works fine here because the number of numbers you want is much smaller than the range.