How do you generate a random number within a range while excluding certain range(s). Eg. range 1-10 but not in 2-4 or 7.
Solutions I've used so far:
- Generate a random an test if it
is within the dis-allowed range.
Based on result either output the
number or try again.
- Map allowed
ranges to a uniform range. Get a
random between 1 and 6 and then map
back (ie. 6 becomes 10).
allowed ranges (1-1,5-6,8-10).
Randomly choose a range (optionally
use weights) and a number in chosen
What is your solution?