title: Fast arbitrary distribution random sampling (inverse transform sampling)
body: <p>The <code>random</code> module (<a href="http://docs.python.org/2/library/random.html" rel="noreferrer">http://docs.python.org/2/library/random.html</a>) has several <em>fixed</em> functions to randomly sample from. For example <code>random.gauss</code> will sample random point from a normal distribution with a given mean and sigma values.</p>
  
  <p>I'm looking for a way to extract a number <code>N</code> of random samples between a given interval using my own distribution <strong>as fast as possible</strong> in <code>python</code>. This is what I mean:</p>
  
  <pre><code>def my_dist(x):
      # Some distribution, assume c1,c2,c3 and c4 are known.
      f = c1*exp(-((x-c2)**c3)/c4)
      return f
  
  # Draw N random samples from my distribution between given limits a,b.
  N = 1000
  N_rand_samples = ran_func_sample(my_dist, a, b, N)
  </code></pre>
  
  <p>where <code>ran_func_sample</code> is what I'm after and <code>a, b</code> are the limits from which to draw the samples. Is there anything of that sort in <code>python</code>?</p>