How to Generate Random Alphas in LoadRunner

Just a quick post for myself so I don’t forget… I needed to generate a random alpha for use in a LoadRunner web vuser script. The native LoadRunner parameters can do random numerics and date/times but I couldn’t find a way to generate only characters, as one might need to generate a random password for example.

So a quick hack to do it in C is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
random_alpha(char* param_name, int length) {
  char buff[32] = "";
  int r,i;
  char c;
  srand((unsigned int)time(0)); //Seed number for rand()
  for (i = 0; i < length; i++) {
	// A-Z = 65-90 = rand() % 25 + 65
    r = rand() % 25 + 65;
    c = (char)r;
		buff[i] = c;
    printf("%c", c);
  }
  lr_save_string(buff, param_name);
  return 0;
}

I keep that as part of my functions library (referenced in globals.h) and can call on it in a script using the following syntax.
random_alpha(char* param_name, int length)

Example:
random_alpha("advertiser_name_suffix", 4);

Returns:
Notify: Saving Parameter "advertiser_name_suffix = SDNG"

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">