Saturday, April 13, 2013

How to generate a random word in Loadrunner?

It’s quite often that while load testing we have to generate random load test data and for that we need some random words or strings.

To meet this objective I have made a function call random_word() in the action part of script, you have to provide length of the word you want and it gives you that. This function uses srand() to seed the pseudo-random number generator and rand() to get a random alphabet.

You can use the below code:
Click here to know more

char buff[32] = "";

random_word(char* param_name, int length)
  int r,i;
  char c;
  srand((unsigned int)time(0));

for (i = 0; i < length; i++)
    r = rand() % 25 + 65;
    c = (char)r;
    buff[i] = c;
    printf("%c", c);

lr_save_string(buff, param_name);
return 0;



    random_word("rnword", 8);
    return 0;

Wow!! Even oxford dictionary can’t explain what does this word means ;). Just kidding, no offence.

No comments:

Post a Comment