How can I generate a random number within a range but exclude some, without keep generating and checking if the generated number is one of those that I want to exclude?
I think the additional question is: What are the numbers you want to exlcude? Do they represent some sort of range or are they totally random?
If it was a range of numbers you want to ignore, you could generate your random numbers from within few sets that represent only valid numbers:
rand(1,9);
rand(15,19);
rand(22,26);
this way you are sure you will never select excluded: <0,10,11,12,13,14,20,21,>27
Then, when you get your 3 numbers, you could again randomly select one of them.
If excluded numbers are all over the place than I'm afraid you'd have to check it every time against some sort of collection of excluded numbers.