My team uses this as a screening question, so I won't give you the answer - but you forgot to mention that both the rand5 and rand7 should have a uniform distribution. :)
I'll give you a hint, though - the solution is not elegant at all. Which is part of the point.
I'll give you a hint, though - the solution is not elegant at all. Which is part of the point.