So this was an interview question.
You are provided with a function rand5()
which generates a random integer in the range [0-5] i.e. {0,1,2,3,4,5}
a) Can you use that function to generate a random integer in the range [0-7]?
b) Can you use that function to generate a random integer in the range [0-7] with each number having equal probability?
You may use the function multiple times.
One of the solution for part a, ((rand5() +rand5())*7)//10
where // represents integer division
would give you the range [0-7] however the probabilities are not equal.
Would love to see your answers and thought process on this.