B prev next
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

<< RANDOM DISTRIBUTIONS >>

The Rejection Method

Algorithm:
1. Set m=0
2. Determine Py_max and the range (ymin and ymax) of the target distribution, Py(y).
3. Generate N random numbers, x(N), y(N), from a uniform distribution.
4. For each value of y:  Set y = ymin + (ymax-ymin)*y

5. LOOP from i=1 to N

       Generate a new random number, ptest distributed 
       uniformly in the range 0 to Py_max:
       Set ptest = Py_max * y(i)

       Test:  if(Py( y(i) ) > ptest) then
                  Set m=m+1      # Entry y(i) passed the test
                  Set z(m)=y(i)  # so we record it in z(m)
               otherwise  
                  remove(reject) y(i) from the squence
       end if Test

   END LOOP i

5. The numbers remaining in the sequence are therefore distributed according 
   to the function Py(y).  
   Plot z