Generate one random number and map it onto your desired ranges of numbers.
If you wanted to generate an integer between 1-4 or 7-10, excluding 5 and 6, you might:
- Generate a random integer in the range
1-8 - If the random number is greater than 4, add
2to the result.
The mapping becomes:
Random number: 1 2 3 4 5 6 7 8
Result: 1 2 3 4 7 8 9 10
Doing it this way, you never need to “re-roll”. The above example is for integers, but it can also be applied to floats.