Editor's note: This article is part of a library of custom VuC functions developed by performance test engineers to handle special situations encountered in scripting applications. For an overview of the library and links to other custom functions, see "A Library of Custom VuC Functions."
The normdist function generates a random number distributed normally over a range of values.
There's no standard VuC function to generate a random number distributed normally
over a range of values. It's possible to include common ANSI C math libraries
to add this functionality, but we find using the normdist function
built by Chris Walters to be easier.
A normal distribution (also known as a bell curve) selects numbers randomly such that the frequency of selection is weighted toward the center, or average value. Figure 1 shows a normal distribution of 1,000 values generated between 0 and 25 (that is, a mean of 12.5 and a standard deviation of 3.2). Normal distributions are generally considered to be the most accurate mathematical model of quantifiable measures of large cross-sections of people when actual data is unavailable. Since performance testing is focused on modeling large cross-sections of users, the ability to create a distribution of this type is extremely valuable.
|
| Figure 1: An ideal normal distribution |
The normdist function takes three parameters of the range to be modeled: minimum value, maximum value, and standard deviation, all in milliseconds. This function, when executed 1000 times with a minimum value of 0 milliseconds, a maximum value of 25000 milliseconds, and a standard deviation of 3200 milliseconds, generates the normal distribution in Figure 2. Note that these are the same parameters used to generate the ideal normal curve, just expressed in milliseconds rather than in seconds. As you can see, this graph is nearly identical to the ideal normal distribution graph in Figure 1.
|
| Figure 2: A normal distribution generated with the normdist function |
There are no external requirements to use this function.
Here's the code for the normdist function, to be included in the script:
int func normdist(min, max, stdev) /* Specifies input values
for normdist function. */
/* min: Minimum value; max: Maximum value;
stdev: degree of deviation */
int min, max, stdev;
{
/* Declare range, iterations, and result as integers - VuC
does not support floating-point math. */
int range, iterate, result;
/* Range of possible values is the difference between the
max and min values. */
range = max - min;
/* This number of iterations ensures the proper shape of
the resulting curve. */
iterate = range / stdev;
/* Integers are not automatically initialized to 0
upon declaration. */
result = 0;
/* Compensation for integer vs. floating-point math. */
stdev += 1;
for (c = iterate; c != 0; c--) /* Loop through iterations. */
result += (uniform (1, 100) * stdev) / 100;
/* Calculate and tally result. */
return result + min; /* Send final result back. */
} |
The normdist function can be placed in each calling script immediately following the #include command, or it can go in a separate .h file referenced by an additional #include command. The function can then be put in either the test script section of the repository or the Rational Test include directory. Putting it in the latter location will give you the benefit of not having to copy this function into every repository you work with.
int normdist(min-value, max-value, std-deviation)
where
min-value
is the minimum possible return value,
max-value
is the maximum possible return value, and
std-deviation
is the standard deviation of the resulting distribution, all expressed as integers.
The normal distribution will most often be used with the delay function. For example, to model a user delay distributed normally between 10 and 35 seconds with a standard deviation of 3.5 seconds, you would use this command:
delay(normdist(10000, 35000, 3500));
In this example, 10000 (milliseconds) is the minimum value, 35000 is the maximum value, and 3500 is the standard deviation. Remember, this command will generate errors if the code for the normdist function isn't included in the script.
If you don't have data to tell you what the standard deviation of a particular distribution should be, you'll have to make an educated estimate. To make that estimate, remember that mathematically 66% of the generated values will be +/-1 standard deviation from the average value. Figure 3 compares the distributions generated by using standard deviations of various sizes.
|
| Figure 3: Example distributions of various standard deviations |
The blue curve represents a small standard deviation (1/25 of the difference between max and min values), in this case generated by the following normdist function call:
normdist(10000, 35000, 1000)
The pink curve represents a fairly typical sized standard deviation (1/8 of the difference between max and min values), generated by this normdist function call:
normdist(10000, 35000, 3500)
The yellow curve represents a large standard deviation (1/3 of the difference between max and min values), generated with this normdist function call:
normdist(10000, 35000, 8000)
When in doubt, it's generally better to err on the side of a large standard deviation than a small when modeling human behavior.
Currently, Scott Barber serves as the lead Systems Test Engineer for AuthenTec. AuthenTec is the leading semiconductor provider of fingerprint sensors for PCs, wireless devices, PDAs, embedded access control devices and automotive markets. He is also member of the Technical Advisory Board for Stanley-Reid Consulting, Inc.
With a background in consulting, training, network architecture, systems design, database design and administration, programming, and management, Scott has become a recognized thought leader in the field of performance testing and analysis. Before joining AuthenTec, he was a software testing consultant, a company commander in the United States Army and a government contractor in the transportation industry.
Scott is a co-founder of WOPR (the Workshop on Performance and Reliability), a semi-annual gathering of performance testing experts from around the world, a member of the Context-Driven School of Software Testing and a signatory of the Agile Manifesto. He is a discussion facilitator for the Performance and VU Testing forum on Rational DeveloperWorks and a moderator for the performance testing and Rational TestStudio related forums on QAForums.com. Scott speaks regularly at a variety of venues about relevant and timely testing topics. Scott'||CHR(59)||'s Web site complements this series and contains much of the rest of his public work. You can address questions/comments to him on either forum or contact him directly via e-mail.
Chris Walters is a recognized innovator in the areas of automated testing and wireless applications. His background is in software and network architecture, security engineering, database design and administration, programming, and management, and he's had years of experience in performance engineering.
Comments (Undergoing maintenance)





