Monday, March 5, 2012

Generate Random Number Function / Rejection Sampling

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

2 comments:

  1. http://www.leetcode.com/2010/11/rejection-sampling.html

    ReplyDelete
  2. rand04() + rand04()/2 + 1

    OR

    do {
    r= rand04() + 5*rand04() //value between 0 and 24
    }while r>=24
    return r/3 (btn 0 and 7)

    ReplyDelete