3
$\begingroup$

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

$\endgroup$
5
$\begingroup$

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

$\endgroup$
  • $\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$ – Geoffrey Critzer Aug 3 '18 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 '18 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 '18 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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