Back to Blog

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.

// DECLARE VARIABLES

char result[100], creditCardNum[1056];
int num, i;

// Call srand before rand
srand(time(NULL));

// 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);
 i=(i+1);
 }

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

Back to Blog