[Solved] How to randomly pick a number of combinations from all the combinations efficiently


If you have F unique first names and L unique last names, then overall number of combinations is N = F * L

So you can generate needed number of non-repeating random integer values in range 0..N-1 (for example, with Fisher-Yates sampling), sort them, and get corresponding name combinations:

for i = 0..M-1
    Generate K[i] = Random(N)
Sort K[]
for i = 0..M-1
   FirstNameIndex = K[i] / L    //integer division
   LastNameIndex = K[i] % L     //integer modulo
   Combination[i] = First[FirstNameIndex] + Last[LastNameIndex]

1

solved How to randomly pick a number of combinations from all the combinations efficiently