code: private int samplePMF(double p[]) {
  
          double r = m_MetaRandom.nextDouble();
  
          double sum = 0.0;
          for (int i = 0; i < p.length; i++) {
              sum += p[i];
              if (r < sum) {
                  return i;
              }
          }
          return -1;
      }
docs: samplePMF.
  
  @param	p	a pmf
  @return	an index i of p with probability p[i], and -1 with probability
  1.0-p[i]