Imagine that you have to create a script for the “Create New User Account” business process. There are several constraints that will make your job difficult…

The username field has the following properties:

  • valid characters are a-z, A-Z, 0-9
  • usernames are not case sensitive. “Stuart” is the same as “stuart”.
  • usernames must start with a letter, not a number.
  • usernames may be a maximum of 8 characters long.
  • username must not be a duplicate

Some other information about your testing:

  • It is unclear when the database in the test environment will be refreshed, but it should happen at least yearly. It will definitely not be refreshed for every test run, and it will not be possible to delete any of the user accounts that you have created.
  • The business process takes a minimum of 1 minute to run from start to finish.
  • There will be a maximum of 99 virtual users executing the business process in the scenario.
  • It is possible that virtual users will execute the business process at exactly the same time.

How do you create usernames that meet all of the above criteria without creating any duplicates? Create a script or provide a descriptive solution.

See the comments section for my solution…


Published On: October 17, 2006Tags: ,


  1. Stuart Moncrieff October 17, 2006 at 1:50 pm

    The quickest and easiest solution to this problem would be to create a big list of unique usernames and keep track of which ones have been used. This is going to be painful if you have do months of testing before the database is refreshed, so it is good if you can find a code-based solution.

    Note that I would be overjoyed if someone can provide a better solution than the one that I have provided.

    1. using a random number will not work as it is not guaranteed that it will not create duplicates.
    2. using the “unique” parameter type will not work as it is only guaranteed to be unique during a single test run.
    3. a date/timestamp combined with a vuser ID or unique number parameter type would satisfy the requirement for no duplicates, but would exceed the maximum number of characters (even if you got sneaky and used a Julian date format)
    4. see my solution here
  2. Chris Meisenzahl October 24, 2006 at 7:50 am

    I usually create them ahead of time using Excel.

  3. Stuart Moncrieff October 26, 2006 at 11:41 am

    I agree that creating usernames outside of LoadRunner (using Excel or whatever) is quick and easy when you’ve only got a few tests to run.

    I would argue that having to keep track of which usernames have been used becomes increasingly painful the more tests you have to run.

    Also, I hate having to update values in a data table every time I need to run a script.

    Spending 30 minutes writing some code that will save you having to manually manage a list of usernames seems like a good trade-off to me.


  4. Jose February 7, 2007 at 8:20 am

    I came across this problem years ago for a functional testing project, I used the time stamp and added a routine to convert numbers to alphas. Used Winrunner

  5. Senthil Ganesh May 15, 2007 at 8:59 pm

    The fastest and easiest way is just record and replaying the “Create New User Account” flow for 100 iteration with different user name.

    Note: Just parameterize the name with a list of values dragged from an excel.


  6. Raju January 16, 2008 at 5:38 am

    Well, Senthil, how you get the values into excel ? Wasn’t that the question ?


  7. Mohan Neupane January 21, 2008 at 3:49 pm

    I agree with Stuart’s solution to create unique names. I also used this way in the past and it works.

    Alternatively, you can also do the following:
    Define year, month, day,hour, and seconds array with pre-defined charactors.
    char arrayYY[8][1]=”{“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”};
    char arrayMM[12][1]=”{“a”,”b”……..”}
    char arraySeconds[60][2]={“AA”,”AB”,…..”};// 60 of them

    Then, read out the real time value of dates and select the characters from the array.
    yy=atoi(lr_eval_string(“{TimeYear}”) // defined parameter
    yy=yy-7 // can be randomised
    sec = atoi(lr_eval_string(“{TimeSecond}”);

    Next part of concatenating will be similar to Stuart’s solutions.
    strncat(SecondName, arraySeconds[sec],2)

    strncat(FirstName, arraryMM[mm], 1);


    Anyway, this alternative solution I hinted out may be a bit longer in code.
    One of the main advantage of using this as I found is to use the pre-defined characters by yourself.


  8. meey s. October 10, 2008 at 3:08 pm

    What I tried was generate a parameter file for the usernames running this code:

    /*Username format: mddHHMMv
    m = month (a – January, b-February… l-December) – this needs to be updated every month
    dd – day (timestamp format)
    HH – hour (24-hr timestamp format)
    MM – minute (timestamp format)
    v – unique VUser ID (parameterized unique for each VUser)

    {dp_month} – Parameter Type: File Parameter Settings: Run Once
    {dp_time} – Parameter Type: Date/Time with format %d%H%M
    {dp_vuserid} – Parameter Type: Vuser ID

    char *udv_filename = “c:\\usernames.dat”;
    long udv_file;

    //Write To File
    if ((udv_file = fopen(udv_filename, “a+” )) == NULL) {
    return -1;
    fprintf(udv_file, “%s%s%s\n”, lr_eval_string(“{dp_month}”), lr_eval_string(“{dp_time}”), lr_eval_string(“{dp_vuserid}”));

    return 0;

    This can be executed using controller for multiple users and using the file generated as a parameter file. Altho the parameters used above can also be embedded directly on the script for Create New User Account.

  9. Dave Pridgeon January 21, 2009 at 5:43 am


    Your unique username code is quite clever – thanks. I have modified it because when I used today’s date, 20 Jan, it returned a 4-char value (supressed zero). My change forces a leading zero.


    char buf[6]; // this buffer is used to hold the converted date value (forced 5 chars).
    char buf_tmp[6]; // this temp buffer is used to hold the converted date value (max 5 chars).
    int datetime; // temporary variable to hold the integer representation of the current data/time.
    int rc;

    Userame must start with a letter, and must end with a unique number.
    Let’s use “t” to indicate that it is a test user, and use a 2-digit Vuser ID (maximum of 99 users in the scenario). Both of these
    attributes will be helpful when searching for usernames that have been created during the test.
    This leaves 5 characters to play with.

    Let’s use a date/time stamp, and convert it to base36 so that we do not exceed our character limit.

    Date does not have to include the year, as the test database will be refreshed at least yearly,
    and the time does not have to include seconds, as it is not possible for a user to complete an iteration in less than 1 minute.

    The date/time stamp value will therefore be “mm dd hh mm” (biggest number will be: 12 31 23 59 – note that this
    will comfortably fit inside an integer).

    This is clearly going to be longer than 5 characters, so convert it to base 36 (

    The biggest possible value will fit into a 5-digit base36 number (7bw9z).


    // %m month number (01-12)
    // %d day of month (01-31)
    // %H hour (00-23)
    // %M minute (00-59)
    lr_save_datetime(“%m%d%H%M” , 0, “DateTimeParam”);
    lr_output_message(“DateTimeParam: %s”, lr_eval_string(“{DateTimeParam}”));

    // Save the date/time value to an integer so that it may be converted to a different base.
    datetime = atoi(lr_eval_string(“{DateTimeParam}”));
    // A date of 01201858 returns a 4-char itoa value
    // datetime = 1201858; // for debugging, use this to return 4 char date time in itoa call
    // datetime = 11201858; // for debugging, use this to return 5 char date time in itoa call

    // Convert to base 36 and save output to buffer.
    itoa(datetime, buf_tmp, 36);

    // Force 5 char string
    sprintf(buf, “%05s”, buf_tmp);

    // Save the converted value back to a parameter.
    lr_save_string(buf, “ConvertedDateTimeParam”);

    // Create the final unique username parameter.
    lr_save_string(lr_eval_string(“T{ConvertedDateTimeParam}{pVuserID}”), “UniqueUsernameParam”);

    // Output the unique username.
    lr_output_message(“Unique username: %s”, lr_eval_string(“{UniqueUsernameParam}”));

    return 0;

  10. Skeptic November 8, 2009 at 11:54 am

    This is guaranteed to generate a unique user name:

    1. create a database table with two fields, (count, time), count is unique and auto increment;
    2. insert current time to the table;
    3. when you read back count and time, it’s guaranteed to be unique.

    When two simultaneous transactions want to write to the database, one has to wait for the other. So, count.time will always be unique. The only problem is length of the user name. Convert 10 digit time into 6 Alpha numeric is easy. The count eventually will grow to a large number, so if you have a 8 characters limit, it may become a problem.

  11. Skeptic November 8, 2009 at 12:06 pm

    There are possibilities and there are probabilities. It is possible, academically, you will have 3844, i.e. 62×62, users signing up in the same second. The probability, in most real life situations however, is quite low. So, if you just use the time.(count % 3844), you can always have exactly 8 characters for the unique user name.

  12. niha July 27, 2010 at 11:32 pm

    need your help in writing an error handling code,. for a java based application to be tested using LR. i can share my desktop where i am recording the script that u can help me with ur idea,
    looking forward to hear from you,


  13. tariq Ahmed April 30, 2011 at 1:49 am


    We are talking about the Correlations first.

    but what i saw over here is you guy are talking about paramerazation

    i think correlation and paramerazation are two different things in load runner,

    Can anybody explain me how to do manuall correlation?

Comments are closed.