He asked me to give him the algorithm for the Fibonacci number in both iterative and using recursion. I failed to solve a problem regarding the algorithm of a rand7 function by using a rand5 function.
Anonymous
Supposing you have the rand5 function which return a number between 1 and 5, you just need to launch rand5 for 7 time to have so an equal probabilistic distribution to cover the number from 1 to 7: public int rand7() { int num = 0; for(int i = 0; i < 7; i++) { num += rand5(); } return num%7+1; }
Check out your Company Bowl for anonymous work chats.