i've got it:

rand5() + rand5()*5 has a result between 6 and 30, with only one possible combination for each answer <-- that's really nice, but what can we do with the 25 different results?

we can take just 21 of them. if we get higher than the 21st result, just do it again.
Code:
int rand7()
{
int answer = 27;
while(answer>26)
answer = rand5() + rand5()*5;
return (answer-5)%7+1;
}



i think that's it.

julz

edited to return the answer

Last edited by JulzMighty; 10/21/07 00:50.

Formerly known as JulzMighty.
I made KarBOOM!