Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7.
Simple and efficient:
int rand7 ( void ) { return 4; // this number has been calculated using // rand5() and is in the range 1..7 }
(Inspired by What's your favorite "programmer" cartoon?).