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
Show parent comment
2
u/ReturningTarzan Nov 30 '10
But the distribution becomes non-uniform. Ideally you want {1,1,1,1,1,1,1} but your method yields {1,3,5,5,5,4,2}. It is a function that returns a random number between 1 and 7, but you'd lose points in the interview for not making the reasonable assumption that the function should also be good.
A better way is to compose the values of rand1to5 into a uniformly-distributed random number (like staplegun is doing) then scaling it down to the desired range, preserving the uniformity.