Compare them to the total sum of the expected ranges. then distribute them between the ranges.
eg. if you need a random value between 0..10 and 100..110
Create a random number between 20. The bottom 10s are in the range 0..10, the rest are in a different interval (or something like that - I can disconnect by one). Interval arithmetic is one of these things that I can never handle on the first try).
The reason for this is because you often deal with not perfect random generators. They start to behave strangely if you distribute consecutive random number variables in several dimensions (for example, first select a random interval, then select a random interval in the selected interval). This can lead to very obvious nonrandom behavior.
If you start with a better random number generator that receives data from true random sources, you can end up wasting precious random bits. If you do this only once per second, this may not be a problem. If you do this often, although the program may stall because pure random sources must catch up with your random bit.
Nils pipenbrinck
source share