If we call rand5() seven times and add up the results, we would get an integer in the inclusive interval [7,35].
Divide this number by 5.0 and we would get a real number in the inclusive interval [1.0,7.0].
Take care of the round-off correctly (how?) and you have rand7().
The issue is is it quicker than adding 7 numbers (and seven calls to rand5()). It can be slower, but most of the time it is quicker.
If on the other hand you have 1.0->5.0 you can actually use the same algorithms, but in that case there is the much quicker approach of just dividing the result, however, this approach looses low bit accuracy.