Load Testing Home

Load Testing Articles

Load Testing Links

Load Testing Books

Load Testing Tools

Load Testing Keywords

Load Testing

Monte Carlo Simulation

What is a Monte Carlo simulation?
A technique which randomly generates values for uncertain variables over and over to simulate a model. The name Monte Carlo derives from the games of chance for which the Principality is famous, such as roulette and baccarat.

On first hearing the notion of a simulation based on chance, you may think of never winning at the roulette. However the technique should be viewed from the point of the Casino. They also have no idea which number the ball is going to land on next. Even the next 100 rolls will be difficult to predict.

What the casino does know though is that if the wheel is spun 30 million times, there will be one million each of 1,2,3 etc. As each spin is an independent act of chance, it is impossible to predict in which order the numbers will come. This predictability allows us to generate transactions that mirror the real world, I.e. we can simulate user activity for the Software Under Test (SUT).

The randomness displayed on the roulette table can be displayed in many situations including stock prices, weather and behaviour of website users.

When is it used?
Monte Carlo simulation is used extensively in statistical analysis and extensively in modelling large financial environments. For example if a fund manager wants to predict how well his fund is going to perform, he might simulate a range of growth rates over the next twenty years, each month is different, conform to the boundaries laid down by the fund manager.

The most common use in Software testing would be I suggest with performance testing.

How is the data generated?
I use two types of data generation. Firstly a spreadsheet is created with a row for each transaction that is to be used as an input to the test. The advantage of this method is the amount of control over the data.

An example is to use the normal distribution. In the real world we know that we never get exactly the same probabilities for such as on roulette. Thus we have to use some other method of generating variability.

Interest rates are a good test. Of course there are periods where they are at the extremes of 1-2% or 12% plus. However these are rare. Over a 25 year mortgage they are likely to be in the 5-8% range. (These are not accurate real world figures.) Thus if we are to calculate transactions on hundreds of mortgages with different rates, we need most of them to be in 5-8% interest, but some will be at the extreme.

The table below shows a spreadsheet calculation. The first row is the Normal Distribution for a given amount. (This calculation is not discussed here.) The second is the percentage of cases that will use the interest rate. The cumulative number of cases is 4th and the interest rate used is last.

As we can see the majority of test inputs will be in the 4.5% - 8.5% range. This mirrors real life.

Normal Distribution% Of CasesNumber Of CasesCumulative TotalInterest Rate
0.1350.01%660.5%
0.6210.05%26321%
2.2750.19%951271.5%
6.6810.56%2784052%
15.8661.32%66110662.5%
30.8542.57%128523513%
504.17%208344343.5%
69.1465.76%288173154%
84.1347.01%3505108204.5%
93.3197.78%3888147085%
97.7258.14%4071187795.5%
99.3798.28%4140229196%
99.8658.32%4161270806.5%
99.3798.28%4140312207%
97.7258.14%4071352917.5%
93.3197.78%3888391798%
84.1347.01%3505426848.5%
69.1465.76%2881455659%
504.17%2083476489.5%
30.8542.57%12854893310%
15.8661.32%6614959410.5%
6.6810.56%2784987211%
2.2750.19%954996711.5%
0.6210.05%264999312%
0.1350.01%64999912.5%
1200.135100%50000

Thus 4141 of transactions will involve an interest rate of 4.5%. 0.5% will the rate in only 6 cases out of 50,000.

The alternative is to generate a random number and according to a defined set of rules set the case input accordingly.

Google
Web www.loadtesting.force9.co.uk

Load Testing Bestsellers
The bestselling books on Amazon.

Articles

Load Testing

test case

performance testing

Test Tools

Web Performance Tuning

Other Related Websites
Automated Testing
Nonfunctional Testing

Visit our site of the month Load Testing at loadtesting.force9.co.uk