How to Generate Random Alphas in LoadRunner

8 August, 2008 – 8:38 am

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"

Share it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netscape
  • Reddit
  • Slashdot
  • Technorati
  • YahooMyWeb

Post a Comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image