Given a function which generates a random integer in the range 1 to 7, write a function which generates a random integer in the range 1 to 10 uniformly.
Useful Links:
http://www.leetcode.com/2010/11/rejection-sampling.html
Useful Links:
http://www.leetcode.com/2010/11/rejection-sampling.html
http://www.leetcode.com/2010/11/rejection-sampling.html
ReplyDeleterand04() + rand04()/2 + 1
ReplyDeleteOR
do {
r= rand04() + 5*rand04() //value between 0 and 24
}while r>=24
return r/3 (btn 0 and 7)