Suppose I define a function in mathematica that has all of the properties of a valid probability density function. Would it be possible to have Mathematica simulate a random sample of a given size of values from this PDF? For example, if I define a function which is the PDF of a beta distribution, can I collect ten thousand "instances" or random samples from this PDF for statistical analysis? If so, how would I do this? Despite my example, I am specifically interested in being able to use my own defined PDF, not necessarily a built-in one that Mathematica already has.

  • $\begingroup$ seen Oleksandr Pavlyk's Creating Your Own Distribution in Wolfram Conference 2011? $\endgroup$
    – kglr
    Commented Feb 14, 2018 at 2:03

1 Answer 1


You can use ProbabilityDistribution for this. Your example pdf:

pdf = PDF[BetaDistribution[1.2, 3.2], x];
pdf //TeXForm

$\begin{cases} 4.554304156477517` (1-x)^{2.2`} x^{0.19999999999999996`} & 0<x<1 \\ 0 & \operatorname{True} \end{cases}$

And using ProbabilityDistribution:

RandomVariate[ProbabilityDistribution[pdf, {x, 0, 1}], 10]

{0.0287507, 0.274103, 0.1581, 0.524414, 0.496944, 0.0579204, 0.204799, 0.230026, 0.140485, 0.438046}

  • $\begingroup$ This is helpful, thank you. But suppose I want to use my own PDF, (say one that I have defined as a function), not one that Mathematica has built-in. How would I do that? $\endgroup$ Commented Feb 14, 2018 at 2:02
  • $\begingroup$ @ereHsaWyhsipS Just replace pdf with your chosen function. $\endgroup$
    – Carl Woll
    Commented Feb 14, 2018 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.