code: static float[] randomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t) {
          // Calc triangle araes
          float areasum = 0.0f;
          for (int i = 2; i < npts; i++) {
              areas[i] = triArea2D(pts, 0, (i - 1) * 3, i * 3);
              areasum += Math.max(0.001f, areas[i]);
          }
          // Find sub triangle weighted by area.
          float thr = s * areasum;
          float acc = 0.0f;
          float u = 1.0f;
          int tri = npts - 1;
          for (int i = 2; i < npts; i++) {
              float dacc = areas[i];
              if (thr >= acc && thr < (acc + dacc)) {
                  u = (thr - acc) / dacc;
                  tri = i;
                  break;
              }
              acc += dacc;
          }
  
          float v = (float) Math.sqrt(t);
  
          float a = 1 - v;
          float b = (1 - u) * v;
          float c = u * v;
          int pa = 0;
          int pb = (tri - 1) * 3;
          int pc = tri * 3;
  
          return new float[] { a * pts[pa] + b * pts[pb] + c * pts[pc],
                  a * pts[pa + 1] + b * pts[pb + 1] + c * pts[pc + 1],
                  a * pts[pa + 2] + b * pts[pb + 2] + c * pts[pc + 2] };
      }
docs: Adapted from Graphics Gems article.