I'm looking for a mathematical approach for generating a random number between [a, b) with holes at [c, d), [e, f), [g, h) and so on where a < b and the ranges are within the bounds.
I've found numerous examples here on how to do make the algorithm work if there is one missing range but can't seem to find a space/time efficient approach that generalizes to multiple ranges. What I mean here is that both:
a. A list of all possible ranges and choosing from that list: doesn't work well for large ranges
b. Generating a random number and checking if it is one of the ranges, otherwise trying again: unbounded terms of runtime
Some salient test cases might be:
generate_random(start=0, end=100, exclude: [(2,50),(51, 100)])
generate_random(start=0, end=1e16, exclude: [(1e6,1e7),(1e3, 1e4)])
Here are some of the examples I have found: