# Generating Random Numbers from an Exponential Distribution

The probability density function (pdf) can be very helpful in analyzing data sets. There are numerous ways to think about the pdf. For example, it was presented from the perspective of histograms in Reliability Hotwire Issue 12. In this article, we consider the pdf from the perspective of a random number generator, and present two ways to generate random numbers from an exponential distribution. First, we will show you how to generate random numbers from an exponential distribution using ReliaSoft Weibull++ by HBM Prenscia. Second, assuming we can generate random numbers between 0 and 1, we will show you how to manually generate random numbers from an exponential distribution using those random numbers. This approach is the basic algorithm used by the Monte Carlo tool; as you will see, the tool can save you considerable time and effort.

## Method 1: Using Weibull++

In Weibull++, choose Insert > Simulation > Monte Carlo. If you have both Weibull++ and ALTA activated on your computer, you will be offered a choice between the Monte Carlo or Stress-Dependent Monte Carlo utilities. For this example, select Monte Carlo.

On the Main tab of the setup window, select the 1P-Exponential distribution and enter 15 in the Mean Time field. On the Settings tab, clear the Use Seed check box and change the Number of points to 20, then click Generate to create the simulated data. The utility will create a new data sheet that contains a list of 20 random numbers from an exponential distribution with a mean of 15.

## Method 2: Without Weibull++

Assuming that we have access to a random number generator that generates random numbers uniformly between 0 and 1, we also can generate random numbers from an exponential distribution without using the Monte Carlo tool. For example, the 10 numbers in Table 1 were generated randomly and uniformly between 0 and 1.

Table 1

 0.2586 0.4925 0.5021 0.7608 0.2064 0.4207 0.0469 0.2537 0.911 0.2914

There is a helpful notation, P(t < a), that often appears in statistics. Here, we will let a = 0.5 and consider P(t < 0.5). In Table 1, there are 7 numbers out of the 10 numbers that are less than 0.5. Thus, the fraction 7/10 = 0.70 represents the fraction of the numbers that are less than 0.5. The true number that is written as P(t < 0.5) should be 1/2 = 0.5, since if there is a large set of random numbers between 0 and 1, we would expect half of those numbers to be less than 0.5.

To get closer to the true P(t < 0.5), instead of 10 numbers, we can generate 20 random numbers between 0 and 1, as shown in Table 2.

Table 2

 0.2732 0.9033 0.608 0.0266 0.828 0.2239 0.1712 0.0083 0.8236 0.1427 0.8945 0.793 0.018 0.0825 0.1944 0.2574 0.8868 0.2977 0.4329 0.2734

In this case, there are 13 numbers out of 20 numbers that are less than 0.5. Thus, the fraction 13/20 = 0.65 represents the fraction of the numbers that are less than 0.5. If we keep on taking larger and larger sets of random numbers and calculating the fraction of numbers that are less than 0.5, our results will get closer and closer to the true P(t < 0.5).

Once we have random numbers between 0 and 1, we can generate random numbers from an exponential distribution using the following formula: (1)

This formula takes a random number R between 0 and 1 and gives a random number T from an exponential distribution with a mean of θ. (We will derive this formula in the Appendix.)

Let us see how we can use this formula to generate random numbers from an exponential distribution with a mean of 10. Inserting 10 into the formula: (2)

Now, instead of R, we can put in a random number between 0 and 1 and use the calculator to calculate T. For example, using the values from Table 1, we can generate 10 random numbers from an exponential distribution with mean 10 in the following way: The numbers 0.2586, 0.4925, 0.5021… come from Table 1. In this way, we obtain the values given in Table 3.

Table 3

 2.992 6.783 6.974 14.305 2.312 5.459 0.48 2.926 24.191 3.445

These random numbers are generated from an exponential distribution with a mean of 10. As in the previous example, we can use the statistical notation of P(t < a). In this case, we let a = 2 and consider P(t < 2). Here, there is just one number that is less than 2. Thus, the fraction 1/10 = 0.10 represents the fraction of the numbers that are less than 2.

As we saw previously, a larger set of random numbers will more closely approach the true value of P(t < 2). Using the values from Table 2, we can create a set of 20 random numbers from an exponential distribution with a mean of 10 in the same way. The generated values are given in Table 4.

Table 4

 3.191 23.361 9.365 0.27 17.603 2.535 1.878 0.083 17.35 1.54 22.49 15.75 0.182 0.861 2.162 2.976 21.786 3.534 5.672 3.194

In this case, there are 6 numbers out of the 20 numbers in Table 4 that are less than 2, or 6/20 = 0.30. We can continue to take larger sets of random numbers from an exponential distribution with a mean of 10. Each time, the fraction of the random numbers that are less than 2 will get closer to the true value denoted by P(t < 2). As it turns out, this value can be calculated analytically, and it is given as: ## Conclusion

In this article, we showed how to generate random numbers from a distribution using the Monte Carlo tool in Weibull++, and also how we can generate those random numbers manually, without the tool. Although we only discussed generating random numbers from an exponential distribution, this procedure can be adjusted to produce random numbers from other distributions such as the two-parameter Weibull distribution.

## Appendix

Here, we will derive Eqn. (2), which relates the random numbers R between 0 and 1 to the random numbers T from an exponential distribution with a mean of 10.

We know that the key formula, as found by inverse transform sampling, that relates the random numbers R between 0 and 1 and the random numbers T from an exponential distribution with a mean of 10 is given by the following formula: It turns out that this integral can be evaluated as follows: From this equation, we solve for T algebraically: Thus, we have derived Eqn. (2).