title: Generate random values given a PDF
body: <p>I have to generate random values according to a determined probability density function (a truncated laplacian):</p>
  
  <p><a href="https://i.stack.imgur.com/sxkO5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sxkO5.png" alt="enter image description here"></a></p>
  
  <pre><code>    Sigma_Phi = 1;
  B = 1/(1-exp(-sqrt(2)*pi/Sigma_Phi));
  Phi = -60:0.001:60;
  
  for iter=1:length(Phi)
      if Phi(iter) &lt; pi &amp;&amp; Phi(iter)&gt;=0
          P(iter) = ((B*exp(-abs(sqrt(2)*Phi(iter)/Sigma_Phi)))/(sqrt(2)*Sigma_Phi));
      elseif Phi(iter) &gt;= -pi &amp;&amp; Phi(iter)&lt;=0
          P(iter) = ((B*exp(-abs(sqrt(2)*Phi(iter)/Sigma_Phi)))/(sqrt(2)*Sigma_Phi));
      else
          P(iter)=0;
      end
  end
  </code></pre>
  
  <p>Then I have to generate random values following that PDF, but I don't know how to do it.</p>