Sample from known function

I am wondering how is it possible to not be able to sample from a function that is known. E.g. suppose the expression of $$f(x)$$ is known but we need to approximate it in order to sample from it, why can't we directly do this on $$f$$?

• When you say function, are you talking about a probability distribution? Can you give an example where you couldn't sample from a known function and had to approximate it? – BatWannaBe Jan 31 at 22:47
• Are methodologies such as rejection sampling acceptable means of sampling from a known function (for purposes of your question)? – jbowman Jan 31 at 22:54
• I think you are asking why we need to use methods like rejection sampling if we already know the Probability Density Function (PDF). Simply because you have a PDF and know its exact formula doesn't mean you can generate independent random samples from it. The PDF simply tells you that, given a value $x$, what is the probability of $x$, $P(X=x)$ but it doesn't tell you how to actually generate a representative, independent sample of the $x's$ so that, together, they appear to have come from from the PDF. So using something like rejection sampling allows you to generate iid samples. – StatsStudent Jan 31 at 23:41