Jmeter Randomization Part 3 – Random String

In parts 1 and 2 we saw how to randomize numbers and dates.  In this post we are going to generate random strings to create random names.  There is a built in randomization function called RandomString which can be used for this purpose.

It can be called at the beginning of your test in the UDV, which will only randomize once.

  • The first name will be 7 random letters from the alphabet.
  • The last name will be 8 random letters from the alphabet.

RandomString(length of random string, string to be randomized, optional)

01_udv

02_udvoutput

You can also randomize values for every thread using a Processor.

In this case we are going to utilize the optional third argument, where we specify the name of the variable to store the random value inside.

RandomString(length of random string, string to be randomized, name of variable)

//randomize first name
${__RandomString(7, abcdefghijklmnopqrstuvwxyz, RNDFIRST)};
log.info("RNDFIRST = " + vars.get("RNDFIRST"));

//randomize last name
${__RandomString(8, abcdefghijklmnopqrstuvwxyz, RNDLAST)};
log.info("RNDLAST = " + vars.get("RNDLAST"));

As seen below, each thread should have unique random values:

03_rndthreads

Leave a comment