I want to generate a random real in the interval [0,1] according to the density function f(x) = 2x.


1 Answer 1


Look up ProbabilityDistribution and RandomVariate. With ProbabilityDistribution, either give it an already normalized PDF or use Method -> "Normalize".

  • $\begingroup$ I am able to generate a random number according to any of the parametric distribution functions in Mathematica by using RandomVariate and ProbabilityDistribution. But I don't know how to get a random number according to a specific density function like f(x) = 2x. $\endgroup$ Aug 3, 2018 at 13:51
  • 1
    $\begingroup$ @GeoffreyCritzer check the links in the answer; your problem is tackled adequately there (see esp. sections Scope>Distribution specification and Options>Method on the first link); notice how you can use ProbabilityDistribution[...] where you'd use eg NormalDistribution[] $\endgroup$
    – user42582
    Aug 3, 2018 at 14:17
  • 2
    $\begingroup$ @GeoffreyCritzer ProbabilityDistribution does precisely what you are asking for. Please look at the doc page examples. $\endgroup$
    – Szabolcs
    Aug 3, 2018 at 15:08

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.