Q: How to generate three and seven random digits, without repeats? For context, I'm trying to randomly generate phone numbers. To do this, I need to generate 999 random, non-repeating, three-digit numbers "XXX" and 9999999 random, non-repeating seven-digit numbers "YYY-YYYY." They must be generated seperately, so that phone numbers with the first three digits are grouped together.
So far, I haven't found an efficient way to do this. Brute forcing it (check all generated phone numbers to see if they're identical, then try again takes. . . well I couldn't be bothered to figure out what the O(n) would be because it's that bad. Binary search helps, but it could still take up to log2(9999999) (or 23) cycles each time, where each cycle involves checking half the length of the previous.
Any ideas would be appreciated.
