Generating Exponential Random Variables

Definition:

An exponential random has a continuous distribution, and can take on any value greater than or equal to zero.  Only one free parameter is available, its mean M >= 0. The rest of its shape is completely fixed and follows a distinctive concave decreasing "ski slope" form.

How to Generate:

  1. The first step is to generate a uniform random number, say U, whose value is between 0 and 1. The easiest method is to use the Linux rand() function to generate a random 32-bit integer and divide by the maximum value, RAND_MAX, to convert it into a real number between 0 and 1, like this:
    1.  
      U = rand()/(RAND_MAX+1.0);
       
  2. The next step is to apply a conversion formula to change it from a uniform (0,1) random variable to an exponential random variable, say X, with mean M, like this:
    1.  
      X = (-M) * log (U);
       
  3. Each additional call to the rand() function will return a different value, so repeating the above two steps will generate a sequence of exponentially distributed random variables. However, note that if you rerun your program a second time, the rand() function will generate the same sequence of "random" numbers again! Thus, in order to conduct a second "experiment" rather than exactly repeating the first one exactly, you must call the srand() function (once only!!!!) to change the hidden random number "seed" that controls the sequence.