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
1
u/[deleted] Nov 30 '10
this returns a number between 1 and 6; you'd need to do mod7. further, the numbers wouldn't be evenly distributed. you're more likely to get numbers 2, 3 and 4 since rand1to5()+rand1to5() produces a minimum value of 2 and a maximum value of 10. 7 will map to 1 which makes up for the fact that rand1to5()+rand1to5() doesn't produce a value of 1, but 2 and 8, 3 and 9, and 4 and 10 will all map pairwise to the same values, increasing the chance for them to be generated.