VuGen: Creating Combination Static/Random Values For Parameters

This post addresses a situation where part of a VuGen parameter value needed to be a hard coded value, and another part had to be totally random. This specific example had to do with a credit card where the total number of digits for the card was 16, but the first two digits needed to start with “47″ to pass the business rules of the site for processing valid card numbers. If the number on the card did not start off with “47″, the card would automatically be rejected.

char result[100], creditCardNum[1056];
int num, i;
// Call srand before rand
// Initial value for i
i = 0;
//Start the randomly generated number with the numbers 4 and then 7
strcpy(creditCardNum, "47");
// Loop through to randomly create each number where 14 is the
// number of additional characters that you want
 while (i < 14) {
 num = rand() % 10+0;
 //Store it the chain
 sprintf( result, "%d", num );
 strcat(creditCardNum, result);
// Save the result as a parameter
 lr_save_string(creditCardNum, "pCreditCardNum");
//Display the results in the output log
 lr_output_message("%s", lr_eval_string("{pCreditCardNum}"));
 return 0;

Can you think of other ways to accomplish this? If so, comments are open below.

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Scott Moore

About Scott Moore (153 articles)

With over 20 years of IT experience with various platforms and technologies, Scott has tested some of the largest applications and infrastructures in the world. He is a Certified Instructor and Certified Product Consultant in HP’s LoadRunner and Performance Center products. He currently holds HP certifications for ASE, ASC, and CI. A thought leader in the APM space, he speaks regularly at IT conferences and events