Skip to main content

Posts

Showing posts from September, 2014

Code to Generate random Name (10 character) and Credit Card (16 digits)

Code to Generate random Name (10 character) and Credit Card (16 digits) and Save them to a .csv file along with Last_four digits of credit card

Under Vuser_init.c Add the function random_ vuser_init()
{
return0;
}
char buff[32] = "";

random_name(int length) {
int r,i;
srand((unsignedint)time(0));  //Seed number for rand()

  r = rand() % 25 + 65; //uppercase for Initial Letter
  buff[0] = (char)r;

//Loop to generate random small characters
for (i = 1; i < length; i++) {
// A-Z = 65-90 && a-z =  97-122
      r = rand() % 26 + 97; //lowercase
    buff[i] = (char)r;

  }
return0;
}    Code which goes into Action() Action()
{
int i;
char *file1 = "C:\\temp\\sample.csv";
long filename1;
unsignedlong num;
char randnum1[10], randnum2[20];
char name[20];
constchar *last_four;

srand(time(NULL));

filename1=fopen(file1,"w");

fprintf(filename1,"Name, Credit_Card, Four_digits\n");

for(i=1;i<=2;i++)
{
random_name(10); //Pass the Length required as argument
lr_output_mess…

Program to Increment the parameter when the parameter has more digits

I have a Parameter. I want to increase the parameter value by 1. Below is the code to capture the parameter and increment it by 1. Action() {
longdouble i;   
lr_save_string("1234567899", "id");
i = atol(lr_eval_string("{id}"));
i =i+1;   
lr_save_int(i, "id");
lr_output_message("Value is: %s", lr_eval_string("{id}"));
return0; } Output: Starting action Action. Action.c(12): Value is: 1234567900 Ending action Action. Ending Vuser...

If we increase the Length of parameter by one more digit (here 11 digits).  The below logic fails as shown below. LL
Action()
{
longdouble i;   
lr_save_string("12345678999", "id");
i = atol(lr_eval_string("{id}"));
i =i+1;   
lr_save_int(i, "id");
lr_output_message("Value is: %s", lr_eval_string("{id}"));
return0;
} Starting action Action. Action.c(12): Value is: -2147483648 Ending action Action.

So, the solution to handle this type of issues is as below: