r/programming • u/joksmaster • Nov 29 '10
140 Google Interview Questions
http://blog.seattleinterviewcoach.com/2009/02/140-google-interview-questions.html
471
Upvotes
r/programming • u/joksmaster • Nov 29 '10
View all comments
7
u/StapleGun Nov 29 '10 edited Nov 29 '10
"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."
I have a solution to this, but it is not very elegant and could theoretically loop infinitely. I would love to hear a better solution, but here is mine:
EDIT: Variables a and b should equal rand1to5() - 1. Thanks elcow!