Skip to main content

Custom VuC functions: normdist

Scott Barber, Performance testing consultant, AuthenTec

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 WaltersNoblestar
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.

Summary:  The VuC function described here generates a random number distributed normally over a range of values. This function is part of a library of customized utilites and VuC functions created by experts in the testing community.

Date:  16 Feb 2005
Level:  Introductory
Activity:  161 views

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.

Purpose/use

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.

An ideal normal distribution
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.

A normal distribution generated with the normdist function
Figure 2: A normal distribution generated with the normdist function

Requirements

There are no external requirements to use this function.


Function code

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.


Command syntax

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.


Examples of use

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.

Example distributions of various standard deviations
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.


About the authors

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)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=4271
ArticleTitle=Custom VuC functions: normdist
publish-date=02162005
author1-email=dwinfo@us.ibm.com
author1-email-cc=
author2-email=
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers