Wrote a function to randomly sample numbers from a given probability density function.