title: Generating random variable from density function
body: <p>How can I generate a random variable of size n= 2914 if I have the density function?.</p>
  
  <p>So the problem is that I have the density f(x) (function well defined)</p>
  
  <pre><code>P     &lt;- function(a,e) { ( (1/6)(1^3) )-((a/2)(1^2)) +(((((a)^2)/2)+e)*1)}
  D     &lt;- function(u,mu,sigma) {dlogis(u,mu,sigma)}
  K     &lt;- function(u,a,e) {(((1/2)*(u^2))- (a*u) +(((a^2)/2)+e))}
  H     &lt;- function(u,mu,sigma){ plogis(u,mu,sigma, lower.tail = TRUE)}
  Fprim &lt;- function(u,a,e,mu,sigma) (1/P(a,e))(D(u,mu,sigma))(K(H(u,mu,sigma),a,e))
  
  Fprim(1,a,e,mu,sigma)
  
  df    &lt;- function(u) Fprim(u,a,e,mu,sigma)
  
  # Parameter n,a,e,mu,sigma
  n&lt;-2914; mu&lt;- -0.42155226; sigma&lt;- 0.60665552; a&lt;- 0.43218138; e&lt;- 0.02149706
  </code></pre>
  
  <p>I think I need to reverse and to use Monte Carlo, I don't know how to do?</p>