# How to generate a random real under a specified density function?

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

Look up ProbabilityDistribution and RandomVariate. With ProbabilityDistribution, either give it an already normalized PDF or use Method -> "Normalize".
• @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[] – user42582 Aug 3 '18 at 14:17
• @GeoffreyCritzer ProbabilityDistribution does precisely what you are asking for. Please look at the doc page examples. – Szabolcs Aug 3 '18 at 15:08