Can anyone give me a hand with techniques to generate integers that satisfy certain restrictions.
For example, say I need to generate integers x and y such that
100 > x
and y < x + 5
And I don’t mean this particular example but some generic techniques to generate integers that satisfy certain conditions.
Well, that’s not that hard:
If you have multiple integers, such as x and y in your example, replace “an integer” by “integers”.
This technique is also known as rejection sampling.
You could implement this with a series of chained iterators, for example. And some constraints work pretty well as generators, such as “positive integers less than 100”, so you’d probably start out with one of those before filtering through all other constraints.
The only other option I’d see that applies to general restrictions would be to analyze your constraints and generate numbers without guessing but knowing how to generate them. This is trivial for constraints such as “0 < x < 100” but beyond that it borders closely on implementing a computer algebra system. Also keep in mind that you have to simultaneously satisfy every constraint … what takes rejection sampling long will make this approach a nightmare to implement.