You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by ZK <st...@gmail.com> on 2017/04/12 13:29:13 UTC

Re: Using regex in inbuilt function __Random

Hi,
useing this code in a beanshell preprocessor will achieve what you want

It will output a string made up of 4 characters, 3 numbers and 2 characters
to a variable called singleStr

// Generates a  4 character random string
import java.util.Random;

chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
int string_length = 4;
randomstring ="";
    for (int i=0; i<string_length; i++) {
        Random randomGenerator = new Random();
      int randomInt = randomGenerator.nextInt(chars.length());
        randomstring += chars.substring(randomInt,randomInt+1);               
    }
temp=randomstring;

// Generates a 3 number random string
chars = "1234567890";
int string_length = 3;
randomstring ="";
    for (int i=0; i<string_length; i++) {
        Random randomGenerator = new Random();
      int randomInt = randomGenerator.nextInt(chars.length());
        randomstring += chars.substring(randomInt,randomInt+1);               
    }
temp=temp+randomstring;

// Generates a 2 character random string
chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
int string_length = 2;
randomstring ="";
    for (int i=0; i<string_length; i++) {
        Random randomGenerator = new Random();
      int randomInt = randomGenerator.nextInt(chars.length());
        randomstring += chars.substring(randomInt,randomInt+1);               
    }
temp=temp+randomstring;

vars.put("singleStr",temp);


Regards,
ZK



--
View this message in context: http://www.jmeter-archive.org/Using-regex-in-inbuilt-function-Random-tp5725448p5725449.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: Using regex in inbuilt function __Random

Posted by ZK <st...@gmail.com>.
you could just use some like:

temp = vars.get("yourVariableStr1");
temp = temp+vars.get("yourVariableStr2");

vars.put("yourConcatenatedVariableStr",temp);


ZK



--
View this message in context: http://www.jmeter-archive.org/Using-regex-in-inbuilt-function-Random-tp5725448p5725451.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org