>although if you're choosing 10 random numbers from a group of 400 000
Of course, since the OP gave no specific numbers, we can't make that assumption. So without more detail, the simpler method is preferred. If the range of numbers is too much for a table, then a binary search tree would be much better than a table for space usage, without much loss in performance. However, the nested loop option will likely be more efficient if the arrays are sure to be very small. The choice of solution depends on the data.