jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ZK <stevesenio...@gmail.com>
Subject Re: Using regex in inbuilt function __Random
Date Wed, 12 Apr 2017 13:29:13 GMT
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


Mime
View raw message