If the number of distinct numbers in the range is not a power of two, you have to be careful, because any procedure which always takes N numbers sees only 2^N different possibilities, and it will not be possible to distribute 2^N different possibilities evenly over a range if the range does not have a power of two different possibilities.
One approach when generating numbers between a..b is to use k random numbers as individual bits in a k-bit number to produce a number in the range a..a+2^k-1, where k is chosen so that a+2^k-1 >= b. If it turns out that the random number you have produced is out of range, start again from scratch. This dodges the problem above by taking a variable number of random bits, depending on whether and how often you generate something out of range and have to start again.