title: Generate random numbers from exponential distribution and model using python
body: <p>My goal is to create a dataset of random points whose histogram looks like an exponential decay function and then plot an exponential decay function through those points. </p>
  
  <p>First I tried to create a series of random numbers (but did not do so successfully since these should be points, not numbers) from an exponential distribution. </p>
  
  <pre><code>from pylab import *
  from scipy.optimize import curve_fit
  import random
  import numpy as np
  import pandas as pd
  
  testx = pd.DataFrame(range(10)).astype(float)
  testx = testx[0]
  
  for i in range(1,11):
     x = random.expovariate(15) # rate = 15 arrivals per second
     data[i] = [x]
  
  testy = pd.DataFrame(data).T.astype(float)
  testy = testy[0]; testy
  
  plot(testx, testy, 'ko')
  </code></pre>
  
  <p>The result could look something like this.</p>
  
  <p><a href="https://i.stack.imgur.com/VJP4U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VJP4U.png" alt="enter image description here"></a></p>
  
  <p>And then I define a function to draw a line through my points:</p>
  
  <pre><code>def func(x, a, e):
  return a*np.exp(-a*x)+e
  
  popt, pcov = curve_fit(f=func, xdata=testx, ydata=testy, p0 = None, sigma = None) 
  
  print popt # parameters
  print pcov # covariance
  
  plot(testx, testy, 'ko')
  
  xx = np.linspace(0, 15, 1000)
  plot(xx, func(xx,*popt))
  
  plt.show()
  </code></pre>
  
  <p>What I'm looking for is: (1) a more elegant way to create an array of random numbers from an exponential (decay) distribution and (2) how to test that my function is indeed going through the data points. </p>
  
  <p><a href="https://i.stack.imgur.com/zIqir.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zIqir.png" alt="enter image description here"></a></p>