First you can go over the 2D density map and for each pair (x, y) find z in it by searching from PDF. This will give you the starting point (x, y) with probability z. Thus, each of the starting points has its own probability of PDF. Now you can order the starting points, randomly select a number and match it with some starting point.
For example, let's say you have n starting points: P1 .. Pn. With probability p1 .. pn (normalized or weighted probabilities, so the sum is 100%). Suppose you choose a random value of p, choose P1 if p <p1, choose P2 if p1 <p <p1 + p2, choose P3 if p1 + p2 <p <p1 + p2 + p3, etc. You can consider it as a histogram over the points P1-PN, which is the same as the cumulative distribution function.
source share