Rand(7) from Rand(5)
Anonymous
int rand7() { while(1) { int n = ((rand5()%2)*4 + (rand5()%2)*2 + (rand5()%2)*1); if(n == 0) continue; return n; } } The rand5()%2 will generate 0 and 1 with equal probability and we need 3 bits since we are going from 000 upto 111. So we call this function thrice for each bit position.
Check out your Company Bowl for anonymous work chats.