I have integers 1,2,3, ..., n, from which I have to select m <n different integers randomly. I intend to put these integers in an array, and then use the Fisher Yates Shuffle:
Randomly select an entry in the array. Change it to the last entry. Then randomly select an entry in the array, with the exception of the last entry. Change this to the second last record. Repeat until the last m records are received.
Question
My understanding is that if you continue up to n times, each possible layout is equally likely with this shuffle. Thus, if you stop after m <n times, each individual layout of the last m records is equally likely. Therefore, the last m entries are m random different integers that I need.
Do I understand correctly?
source share